0
我想在我的Xcode項目中播放遠程MP3文件,但是下面的實現使用MPMoviePlayerController並不適合我,並且正在拋出異常。在iOS中通過HTTP播放遠程MP3文件5
AVPlayerItem被重新分配,而關鍵值觀察者仍然在其中註冊了 。
我.h文件中
#import <MediaPlayer/MediaPlayer.h>
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
我.m文件
@synthesize moviePlayer = _moviePlayer;
- (void)playEnglish
{
NSURL *url = [NSURL URLWithString:_audioUrlEnglish];
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
很棒的回答。謝謝。 – Nick