我正在制作一个视频,该视频以视频的特定间隔显示覆盖。我设法播放了视频。现在,我的目标是观看/观察currentPlaybackTime值,并在视频播放2秒时暂停播放。

经过一些研究发现currentPlaybackTime不支持KOV。所以我需要实现this solution,但是我不知道将代码放在哪里-我对Objective C还是很陌生。被放置在其他地方...

我应该为此创建一个新的控制器吗?还是我要重写MediaPlayer框架中的方法?

这是我的代码:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController

@property (strong, nonatomic) MPMoviePlayerController *movieController;

@property(nonatomic) NSTimeInterval currentPlaybackTime;

@end



#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)viewDidAppear:(BOOL)animated {

    self.movieController = [[MPMoviePlayerController alloc] init];


    NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
    self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    [self.movieController.view setFrame:CGRectMake (0, 0, 480, 326)];
    [self.view addSubview:self.movieController.view];


    [self.movieController play];
    [self.movieController currentPlaybackTime];




}



@end

最佳答案

您可以在同一视图控制器中的找到的解决方案中实现以下方法。

之后

[self.movieController play];


调用以下方法

[self BeginPlayerPolling];


在初始化您的movieController的viewDidAppear中将此类注册为观察者

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object: self.movieController];
self.movieController = [[MPMoviePlayerController alloc] init];


并实现此通知观察者的方法

- (void)movieFinishedCallback:(NSNotification*)aNotification
{
    // Remove the movie player view controller from the "playback did finish" notification observers
    [[NSNotificationCenter defaultCenter] removeObserver: self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object: self.movieController];
    [self EndPlayerPolling];
}

关于ios - 观察currentPlaybackTime并间隔显示一个叠加层,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20807914/

10-11 22:24
查看更多