如何确定用户在MPMoviePlayer实例中的当前位置?

ang*_*ent 2 iphone mpmovieplayercontroller

我有一部很长的电影,我将放在一个应用程序中,我想知道什么是让用户回到他们中断点的最佳方式.有人能指出我正确的方向吗?

因此,如果用户正在观看电影,点击完成,是否有当前时间的通知或我可以存储的内容并在那个时间再次加载实例?

谢谢!

Jas*_*son 5

我发现了一种不使用私有API组件的OS 3.0技术.

您可以注册接收MPAVControllerTimeDidJumpNotification通知,并从该通知的userInfo字典中获取MPAVControllerTimeParameter NSNumber.

例如,在您开始播放寄存器以接收通知之前:

#define MPAVControllerTimeDidJumpNotification @"MPAVControllerTimeDidJumpNotification"

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTimeChanged:) name:MPAVControllerTimeDidJumpNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

然后开始播放电影.添加一个方法,在电影播放时每次更改时都会调用该方法:

-(void)handleTimeChanged:(NSNotification *)notification
{
    NSDictionary * userInfo = notification.userInfo;
    int lastPositionInSeconds = [[userInfo valueForKey:@"MPAVControllerTimeParameter"] intValue];
    NSLog( @"Last time was %d", lastPositionInSeconds );
}
Run Code Online (Sandbox Code Playgroud)

当电影停止播放时(通过监听MPMoviePlayerPlaybackDidFinishNotification通知你知道这一点)停止监听MPAVControllerTimeDidJumpNotification通知.