2010-09-13 94 views
1

我試圖從iPhone設備上的服務器上播放視頻。我使用下面的方法來實現,但是,它只能在模擬器中使用;和我的iPhone 4上。它不適用於iPhone 3G?MPMoviePlayerViewController意外退出

如果我在iPhone 3G上調用此方法,它會打開視頻模式屏幕,開始加載視頻,然後突然關閉模式屏幕。在控制檯中不顯示錯誤。

iPhone 3G已安裝4.0版本。我的iPhone 4有4.1版本。

有沒有其他人經歷過這個?

-(IBAction)playMedia{ 

NSString* url = [self.data objectForKey:@"url"];  

//initialize the movie player 
self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]]; 

//show a background image while the user waits 
moviePlayerViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 


//show the movie 
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController]; 

[moviePlayerViewController release]; 

} 
+0

您是否可以通過iOS 4獲得iPhone 3G以通過其他應用播放遠程視頻?一些人(包括我自己)在3G設備上運行iOS 4時遇到了很多問題。如果您在其他應用中遇到穩定性問題,請嘗試重新啓動設備,然後重試? – pix0r 2010-09-13 22:26:03

回答

0

我會做上面的有點不同:

-(IBAction)playMedia{ 

NSString* url = [self.data objectForKey:@"url"];  

//initialize the movie player 

MPMoviePlayerViewController *tmpPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]]; 
self.moviePlayerViewController = tmpPlayer; 

//show a background image while the user waits 
UIColor *tmpColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
self.moviePlayerViewController.view.backgroundColor = tmpColor; 

self.moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 

//show the movie 
[self presentMoviePlayerViewControllerAnimated:self.moviePlayerViewController]; 

[tmpPlayer release]; 
[tmpColor release]; 
} 
+0

嗨,這段代碼適用於Xcode和iPhone3GS中的iOS5 .. – 2012-06-07 06:38:29

1

確定我有視頻,兩個iPhone 4和iPhone 3G的工作。基本上問題是文件格式。我正在播放.mov文件。當我將格式更改爲.mp4時,它現在可以在兩臺設備上使用。代碼沒有變化。

希望這可以幫助他人解決同樣的問題。

+0

我用Quicktime將它改爲.m4v文件,它運行良好。在QT10中打開視頻,點擊文件 - >另存爲,然後選擇iPhone作爲輸出。然後更改代碼以反映擴展更改。像魅力一樣工作! – 2011-05-12 13:24:10