Why does my music not play first time?

235 Views Asked by At

I have this code:

[self.musicPlayer stop];
[self.musicPlayer setQueueWithQuery:persistentQuery];
[self.musicPlayer play];

But for some reason, you only hear the first split second of a song the first time. Then the second time, you hear the song. Doing a sort of patch-fix with:

[self.musicPlayer stop];
[self.musicPlayer setQueueWithQuery:persistentQuery];
[self.musicPlayer play];
[self.musicPlayer stop];
[self.musicPlayer play];

doesn't work - this only makes it play the first split second every time.

1

There are 1 best solutions below

1
On

I had a similar problem in that a MusicPlayer object would not play when the play method was first called. I found I had to setup the musicPlayer object earlier in the app life cycle i.e. set it up before you require it.