如何以编程方式从保存的时间间隔在 iPhone 中播放本地 mp4 视频
我有一个场景,我希望用户能够从他之前离开的位置开始播放视频。我目前正在使用 MPMoviePlayerController。我可以使用 MPMoviePlayerController 的通知来存储播放持续时间。
所以我需要的是,每当用户开始播放同一视频时,他都可以选择从他离开的时间开始播放。是否可以?如果是的话我该怎么做。我应该使用 MPMoviePlayerController 吗?因为我已经查看了文档中的所有方法,但没有找到任何内容。下面是我当前播放视频的代码。
- (void) playDownloadedFile:(NSString*) filePath
{
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieDurationAvailableCallback:)
name:MPMovieDurationAvailableNotification
object:player];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(moviePlaybackStateDidChangeCallback:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:player];
player.view.frame = CGRectMake(50, 25, 924, 718);
[self.view addSubview:player.view];
//---play movie---
[player play];
videoState = [[VideoState alloc] init];
}
- (void) movieDurationAvailableCallback:(NSNotification*) aNotification {
MPMoviePlayerController *moviePlayer = [aNotification object];
videoState.videoDuration = moviePlayer.duration;
}
- (void) moviePlaybackStateDidChangeCallback:(NSNotification*) aNotification {
MPMoviePlayerController *moviePlayer = [aNotification object];
videoState.playBackState = moviePlayer.playbackState;
}
I have a scenario in which I want user to be able to start a video from the point he left previously. I am currently using MPMoviePlayerController. I am able to store playback duration using MPMoviePlayerController's notifications.
So what I need is whenever user is starting same video he has an option to start it from the duration he left. Is it possible? and if it is how can I do that. Should I use MPMoviePlayerController, since I have looked in all methods in documentation and did not find anything. Below is my current code to play video.
- (void) playDownloadedFile:(NSString*) filePath
{
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieDurationAvailableCallback:)
name:MPMovieDurationAvailableNotification
object:player];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(moviePlaybackStateDidChangeCallback:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:player];
player.view.frame = CGRectMake(50, 25, 924, 718);
[self.view addSubview:player.view];
//---play movie---
[player play];
videoState = [[VideoState alloc] init];
}
- (void) movieDurationAvailableCallback:(NSNotification*) aNotification {
MPMoviePlayerController *moviePlayer = [aNotification object];
videoState.videoDuration = moviePlayer.duration;
}
- (void) moviePlaybackStateDidChangeCallback:(NSNotification*) aNotification {
MPMoviePlayerController *moviePlayer = [aNotification object];
videoState.playBackState = moviePlayer.playbackState;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MPMoviePlayerController
有一个名为initialPlaybackTime
的属性。将其设置为从观看者停止的地方开始。MPMoviePlayerController
has a property calledinitialPlaybackTime
. Set it to start where the viewer left off.