Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

iphone - MPMoviePlayerController and HTTP Live Streaming

every one. I'm trying to figure out how to play live stream using MPMoviePlayerController. For testing i'm using Apples test stream sample http://devimages.apple.com/iphone/samples/bipbopall.html. It's perfectly working in UIWebView, but i can't make it work with MPMoviePlayerController. There is my piece of code:

NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbopall.html"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:nil]; 

[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];

[self.view addSubview:[mp view]];

[mp prepareToPlay];
[mp play];

Actually the controller recieves MPMoviePlayerPlaybackDidFinishNotification without playing anything. Where is the problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your problem is probably with the URL. MPMoviePlayerController wants the URL directly to the file you want to play. You are providing the URL for an HTML page which the movie player doesn't understand. That is why it does work in UIWebView since a web browser understands HTML. If you want more information about what's wrong you can check the error doing the following, quoted from Apple's documentation:

To check for errors in URL loading, register for the MPMoviePlayerContentPreloadDidFinishNotification or MPMoviePlayerPlaybackDidFinishNotification notifications. On error, these notifications contain an NSError object available using the @"error" key in the notification’s userInfo dictionary.

It would look something like:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    NSError *error = [[notification userInfo] objectForKey:@"error"];
    if (error) {
        NSLog(@"Did finish with error: %@", error);
    }
}

If you want to try and play that sample you can try and access the URL for the stream directly, which would be: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...