2012-05-13 58 views
1

我正在使用MPMoviePlayerController播放「.3gp」視頻,我從服務器獲取數據並將其保存在NSData對象中,然後將其寫入Document目錄中的文件,這裏是我的代碼MPMoviePlayerController不工作在iOS 5上

在.hi

在.m文件中定義錄像機爲

@interface MainViewController : UIViewController { 
    MPMoviePlayerController* videoPlayer; } 
@property (strong, nonatomic) MPMoviePlayerController* videoPlayer; 

-(void)videoWillStartPlayWithUrl:(NSData *)d 
{ 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,  YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.3gp"]; 

    [d writeToFile:path atomically:YES]; 


    NSURL *url = [NSURL fileURLWithPath:path]; 
    adBannerView.hidden = YES; 
    self.videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url]; 
    self.videoPlayer.controlStyle = MPMovieControlStyleEmbedded; 
    self.videoPlayer.shouldAutoplay = YES; 

    [self.videoPlayer.view setFrame: self.view.bounds]; 

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

    [self.videoPlayer setFullscreen:YES animated:YES]; 
    [self.videoPlayer prepareToPlay]; 
    [self.videoPlayer play]; 

} 

它在iOS中可以正常使用5但在iOS 5中它只是顯示一個黑屏並直接退出,我似乎無法找到阻止視頻在iOS 5中播放的問題,非常感謝

回答

1

多小時的搜索和調試問題後竟然是有關的影片,我試圖打的編解碼器,

,而他們中的iOS 4完美工作,iOS 5的需要的特殊的編解碼器.3GP視頻在MPMoviePlayerController中提到。編程指南,所以解決方案是改變我的視頻編解碼器和代碼完美的iOS 5

0

在您的頭文件中,執行此操作: -

MPMoviePlayerController *myPlayer; 

,改變你的屬性爲: -

@property(nonatomic, strong) MPMoviePlayerController *myPlayer; 

啓動moviePlayer如下: -

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:Url]; 
self.myPlayer= player; 

您可能啓用了您的弧。

+0

我應該發送消息給玩家或self.myPlayer? [self.myPlayer play]或[player play] – ahmad

+0

self.myplayer.also唯一需要注意的是你必須在這裏使用強關鍵詞 –

+0

thnx很多,但它不工作!接收到「MPMoviePlayerPlaybackDidFinishNotification」,並且播放器從視圖中移除而不顯示除播放器界面和其頂部的播放器界面和加載指示符之外的任何內容!任何其他的想法? – ahmad

相關問題