gpt4 book ai didi

ios - MPMoviePlayerController 下一个上一个按钮不正确的通知

转载 作者:行者123 更新时间:2023-11-28 17:51:59 24 4
gpt4 key购买 nike

我有 MPMoviePlayerController 并且我只想检测下一个/上一个按钮以便相应地播放播放列表,我添加了通知,但它总是返回 MPMoviePlaybackStateStopped 状态而不是MPMoviePlaybackStateSeekingForwardMPMoviePlaybackStateSeekingBackward

代码如下:

[[NSNotificationCenter defaultCenter] addObserver:self // the object listening / "observing" to the notification
selector:@selector(stateChanged:) // method to call when the notification was pushed
name:MPMoviePlayerPlaybackStateDidChangeNotification // notification the observer should listen to
object:nil];

在回调函数中:

-(void)stateChanged:(NSNotification *)notification{
MPMoviePlaybackState state = self.moviePlayerViewController.moviePlayer.playbackState;
switch (state) {
case MPMoviePlaybackStateStopped:
NSLog(@"Stopped");
break;
case MPMoviePlaybackStateInterrupted:
NSLog(@"Interrupted");
break;
case MPMoviePlaybackStateSeekingForward:
NSLog(@"forward");
currentIndex++;
ForcePlay = true;
[self PlayVideo:currentIndex];
break;
case MPMoviePlaybackStateSeekingBackward:
NSLog(@"backward");
currentIndex--;
ForcePlay = true;
[self PlayVideo:currentIndex];
break;
case MPMoviePlaybackStatePaused:
NSLog(@"paused");
break;
case MPMoviePlaybackStatePlaying:
NSLog(@"playing");
break;
}
}

最佳答案

MPMoviePlayerController 的默认控件只有基本功能。点击 Prev/Next 只会调用一个状态,即 MPMoviePlaybackStateStopped

如果您想要检测上一个/下一个的能力,您必须实现自己的自定义控件并通过使用 MPMovieControlStyleNone 隐藏默认控件来分别对每个按钮执行操作

例如在 Obj-C 中:

[prevBtn addTarget:self action:@selector(onClick:) 
forControlEvents:UIControlEventTouchUpInside];

[nextBtn addTarget:self action:@selector(onClick:)
forControlEvents:UIControlEventTouchUpInside];

关于ios - MPMoviePlayerController 下一个上一个按钮不正确的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30194171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com