我想在iPhone模擬器中播放視頻。我曾嘗試使用MPMoviePlayerViewController,但它沒有播放。任何人有想法如何做到這一點?如果有什麼好的教程,請幫我找一個。感謝名單。如何在iPhone模擬器中播放視頻
注:有關MPMoviePlayerViewController沒有的MPMoviePlayerController
我想在iPhone模擬器中播放視頻。我曾嘗試使用MPMoviePlayerViewController,但它沒有播放。任何人有想法如何做到這一點?如果有什麼好的教程,請幫我找一個。感謝名單。如何在iPhone模擬器中播放視頻
注:有關MPMoviePlayerViewController沒有的MPMoviePlayerController
只需將問題和Xcode項目拖放視頻文件
提供視頻的URL 「videourl」
NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];
它將運行完美模擬器
This link也可以幫到你
雅它的工作,即使沒有將文件添加到項目中,我們不能這樣做? – Newbee
假設ARC。
例如,你可以調用你的viewDidLoad方法和控制器添加到您的視圖中使用:
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"test" ofType:@"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[self.view addSubview:theMovie.view];
[self addChildViewController:theMovie];
}
在我的頭文件我寫:
MPMoviePlayerController *moviePlayer;
與此屬性:
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
以及我初始化moviePlayer的方法:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;
使用以下代碼
MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:yourVideoURL];
moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer1];
[moviePlayer1 play];
見[此](http://stackoverflow.com/questions/4941803/mpmovieplayercontroller-tutorial-needed)。 – Adam
請提及投票原因,以便日後改進。 – Newbee
downvotes的原因是你的問題不是特定的,如果你想在stackoverflow本身搜索它,你會找到解決方案。檢查出來之前問任何問題http://stackoverflow.com/faq – IronManGill