如何以编程方式从保存的时间间隔在 iPhone 中播放本地 mp4 视频

发布于 2024-11-08 05:37:21 字数 1626 浏览 0 评论 0原文

我有一个场景,我希望用户能够从他之前离开的位置开始播放视频。我目前正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2024-11-15 05:37:21

MPMoviePlayerController 有一个名为 initialPlaybackTime 的属性。将其设置为从观看者停止的地方开始。

MPMoviePlayerController has a property called initialPlaybackTime. Set it to start where the viewer left off.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文