2012-05-31 111 views
0

我試圖在設備上播放視頻。視頻是這個 video電影播放錯誤

和我的代碼:

NSString *urlStr = @"http://easyhtml5video.com/images/happyfit2.mp4"; 
NSURL *url = [NSURL fileURLWithPath:urlStr]; 
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
[self.view addSubview:moviePlayer.view]; 
moviePlayer.view.frame = CGRectMake(0, 0, 320, 400); 
[moviePlayer play]; 

當我開始應用的電影屏幕看到,但電影犯規發揮。你能幫我解決錯誤嗎?

回答

0

查看此視頻以供參考。這對我的作品 -

- (IBAction)playMovie:(id)sender 
{ 
    NSString *filepath = @"http://easyhtml5video.com/images/happyfit2.mp4"; 
    NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) 
                   name:MPMoviePlayerPlaybackDidFinishNotification 
                  object:moviePlayerController]; 

    [self.view addSubview:moviePlayerController.view]; 
    moviePlayerController.fullscreen = YES; 
    [moviePlayerController play]; 
} 

- (void)moviePlaybackComplete:(NSNotification *)notification 
{ 
    MPMoviePlayerController *moviePlayerController = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
             name:MPMoviePlayerPlaybackDidFinishNotification 
                       object:moviePlayerController]; 

    [moviePlayerController.view removeFromSuperview]; 
    [moviePlayerController release]; 
} 
+0

它沒有發揮。屏幕被看到了一秒,但視頻沒有play.which框架你導入?以及你的.h類 – yatanadam

+0

試試這個 - http://mobile.tutsplus.com/tutorials/iphone/mediaplayer-framework_mpmovieplayercontroller_ios4/。這也有源代碼。 –

+0

錯誤是這樣的:類AVPlayerItem的實例0x7a58230被釋放,而鍵值觀察者仍然註冊它。觀察信息被泄露,甚至可能被錯誤地附加到其他物體上。在NSKVODeallocateBreak上設置一個斷點,在調試器中停止。以下是當前的觀察信息: 上下文:0x0,屬性:0x78593e0> – yatanadam

1

嘗試使用 NSURL *url = [NSURL URLWithPath:urlStr];

,而不是 NSURL *url = [NSURL fileURLWithPath:urlStr]; 這是一個網頁的網址不是文件的URL。