如何在 UIWebView 中循环播放 mp4 文件
How to loop mp4 file in UIWebView
我想在 UIWebView 中循环一个 mp4 文件。
例如
如果你去这个link(http://techslides.com/demos/sample-videos/small.mp4)打开UIWebView,就无法循环播放了。但是我想循环再循环看这个mp4视频。
请给我任何克服的技巧!
干杯,
您可以简单地使用 MPMoviePlayerController
和 setRepeatMode:MPMovieRepeatModeOne
。
这应该允许任何视频的无缝循环,而且实现起来很简单。
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Your Cool Video File" ofType:@"mp4"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[playerController.moviePlayer play];
重要的是要记得像这样订阅结束播放通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
- 在 moviePlayBackDidFinished 方法中手动开始播放
我想在 UIWebView 中循环一个 mp4 文件。
例如 如果你去这个link(http://techslides.com/demos/sample-videos/small.mp4)打开UIWebView,就无法循环播放了。但是我想循环再循环看这个mp4视频。
请给我任何克服的技巧!
干杯,
您可以简单地使用 MPMoviePlayerController
和 setRepeatMode:MPMovieRepeatModeOne
。
这应该允许任何视频的无缝循环,而且实现起来很简单。
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Your Cool Video File" ofType:@"mp4"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[playerController.moviePlayer play];
重要的是要记得像这样订阅结束播放通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
- 在 moviePlayBackDidFinished 方法中手动开始播放