我正在將應用程序從iOS6移植到iOS7。有一個奇怪的問題,使得在完成按鈕調用後屏幕變黑。我試過this,this和this。MPMoviePlayerController不播放視頻幀ios7
有沒有適當的答案,我不覺得在理論上使用以前的方法應該有任何問題。
請提供一些線索,以解釋爲什麼會出現此問題。
感謝
我正在將應用程序從iOS6移植到iOS7。有一個奇怪的問題,使得在完成按鈕調用後屏幕變黑。我試過this,this和this。MPMoviePlayerController不播放視頻幀ios7
有沒有適當的答案,我不覺得在理論上使用以前的方法應該有任何問題。
請提供一些線索,以解釋爲什麼會出現此問題。
感謝
在主窗口添加您的電影播放器視圖,如:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:@"map.mp4"]];
[player prepareToPlay];
[player.view setFrame: self.view.bounds];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview: player.view];
[player play];
希望如此,它會爲你工作!
嘗試這種方式..
ViewController.m
MPMoviePlayerViewController *mp=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[arr_videos objectAtIndex:indexPath.row]valueForKey:@"Video_path"]]];
MPMoviePlayerController *pc=[mp moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self presentViewController:mp animated:YES completion:nil];
[pc prepareToPlay];
[pc play];
這是純粹的廢話。您正在分配一個'MPMoviePlayerViewController',並且永遠不會將其分配給頭中已準備好的屬性。 – Till
@Till,只是看到我更新的答案。 – user1673099
使用ARC時會失敗。 – Till
這可以幫助 導入的MediaPlayer在.h文件中
#import <MediaPlayer/MediaPlayer.h>
使屬性
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
之後,你可以通過這個
-(void)playMovie:(id)sender
{
NSURL *url = [NSURL URLWithString:
@"http://www.xyz.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
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];
}
}
我可以知道爲什麼我有一個向下投票播放視頻? – Xander
您嘗試了三種方法 - 即使沒有人看起來有您描述的確切問題,但他們都會在您的應用程序中產生相同的問題。這幾乎解決了這個事實,即它是你從未向我們展示過的其他代碼,引發了這個問題。所有給出的答案都必須是純粹的猜測 - >你的問題,因爲它沒有用,因此我的投票是反對票。 – Till