Я пишу приложение для iPhone, которое воспроизводит потоковую передачу через http, вот мой код
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerPlaybackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
//livePlayer is MPMoviePlayerController declared in header
livePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString: liveStreamURL]];
livePlayer.controlStyle = MPMovieControlStyleNone;
[livePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
}
- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {
if ([livePlayer loadState] != MPMovieLoadStateUnknown) {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[livePlayer play];
}
}
-(void) moviePlayerPlaybackStateDidChange:(NSNotification*)notification {
NSLog(@"playbackDidChanged");
MPMoviePlayerController *moviePlayer = notification.object;
MPMoviePlaybackState playbackState = moviePlayer.playbackState;
if(playbackState == MPMoviePlaybackStateStopped) {
NSLog(@"MPMoviePlaybackStateStopped");
} else if(playbackState == MPMoviePlaybackStatePlaying) {
NSLog(@"MPMoviePlaybackStatePlaying");
} else if(playbackState == MPMoviePlaybackStatePaused) {
NSLog(@"MPMoviePlaybackStatePaused");
} else if(playbackState == MPMoviePlaybackStateInterrupted) {
NSLog(@"MPMoviePlaybackStateInterrupted");
} else if(playbackState == MPMoviePlaybackStateSeekingForward) {
NSLog(@"MPMoviePlaybackStateSeekingForward");
} else if(playbackState == MPMoviePlaybackStateSeekingBackward) {
NSLog(@"MPMoviePlaybackStateSeekingBackward");
}
}
, метод moviePlayerPlaybackStateDidChange вызывается только один раз, когда он начинает воспроизводить поток.из-за плохого состояния сети, когда-нибудь он останавливает воспроизведение и показывает черный экран, я хочу отображать UIActivityIndicateView при буферизации потока, может кто-нибудь сказать мне, как это сделать?Я использую SDK4.0