我不明白爲什麼我的視頻不會在iOS設備上播放。請讓我知道我缺少什麼。另外,是的,我將MediaPlayer.framework導入到.h頁面中。我創建了一個按鈕,並在點擊後調用了從網站播放視頻的操作。檢查iOS視頻不工作(流媒體)Xcode
-(IBAction)playMovie:(id)sender{
NSURL *url=[NSURL URLWithString:@"http://www.videopage/video"]:
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
NSString *version = [[UIDevice currentDevice] systemVersion];
BOOL isAtLeast84 = [version floatValue] >= 8.35;
if (isAtLeast84) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackStateChanged:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
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];
} }