MPMoviePlayerController stops playing the video after 5s

末鹿安然 提交于 2019-12-24 03:38:07

问题


I tried to play a video in iOS but it just played 5s for any video. This is my code:

NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"videoviewdemo" ofType:@"mp4"];
NSURL *movieURL = [[NSURL alloc]initFileURLWithPath:moviePath];

MPMoviePlayerController *theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.controlStyle = MPMovieControlStyleDefault;
[theMoviPlayer setMovieSourceType:MPMovieSourceTypeFile];
theMoviPlayer.shouldAutoplay = YES;

theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));

[theMoviPlayer.view setFrame:self.view.frame];
[theMoviPlayer prepareToPlay];
[self.view addSubview:theMoviPlayer.view];

回答1:


Declare an ivar @property (nonatomic,strong) MPMoviePlayerController *myMovieController;

assign theMoviPlayer to it as follows,

self.myMovieController = theMoviPlayer;
[self.view addSubview: self.myMovieController.view];

and then play the movie.

The issue seems to be that theMoviPlayer is not retained.



来源:https://stackoverflow.com/questions/22219227/mpmovieplayercontroller-stops-playing-the-video-after-5s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!