Thanks for noticing this question. I am using a singleton to play music in my app, via AVPlayer
, like this way:
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];
AVURLAsset *musicAsset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:musicAsset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:_playerItem];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[player play];
It works fine. But my app has some music pages(HTML5), so user can also visit the web page, and play music there. The music from UIWebView
and from AVPlayer
can be played in the same time, seems to be very strange. Is there any ways to detecting if UIWebView
will playing music, so I can stop the native AVPlayer
? Thanks!