简体   繁体   English

更改 AVPlayer 视频 MacOS Objective-C Cocoa

[英]Change AVPlayer Video MacOS Objective-C Cocoa

For MacOS, not iOS.对于 MacOS,不是 iOS。 I am playing a video in an AVPlayerView in an XIB.我在 XIB 的 AVPlayerView 中播放视频。 Just experimenting with video playback.只是尝试视频播放。 I would like to be able to choose a selection from the File Menu (For instance File / Videos / Video 1, Video2, Video3, etc) and change the currently playing video in the XIB when I select the menu item.当我 select 菜单项时,我希望能够从文件菜单中选择一个选项(例如文件/视频/视频 1、视频2、视频3 等)并更改 XIB 中当前正在播放的视频。

Currently I am using this to play a video:目前我正在使用它来播放视频:

- (void)windowDidChangeOcclusionState:(NSNotification *)notification
{
    if (self.window.occlusionState & NSWindowOcclusionStateVisible)
    {
        loopPlayer = YES;
        [_aspectView setAspectRatio:NSMakeSize(16, 9)];
        NSBundle *mb = [NSBundle mainBundle];
        NSURL *demoURL = [mb URLForResource:@"Video1" withExtension:@"mp4"];
        player = [[AVPlayer alloc] initWithURL:demoURL];
        self.playerView.player = player;
        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
        [nc addObserver:self selector:@selector(movieEndDetected:)
                   name:@"AVPlayerItemDidPlayToEndTimeNotification"
                 object:player.currentItem];
        [player play];
    }
    else
    {
        [player pause];
        [player seekToTime:kCMTimeZero];
    }
}

and to loop the video playing:并循环播放视频:

- (void) movieEndDetected:(NSNotification *) note
{
    if (loopPlayer) {
        [player seekToTime:kCMTimeZero];
        [player play];
    }
}

But I would like to change the playing video in the XIB on the fly by choosing a menu button.但我想通过选择菜单按钮来动态更改 XIB 中的播放视频。 Any ideas how this can be done?任何想法如何做到这一点? I have heard of AVPlayerQueue maybe working for this kind of thing, but I am very new and can't get it working on MacOS.我听说过 AVPlayerQueue 可能适用于这种事情,但我很新,无法让它在 MacOS 上运行。

My solution was to use many avplayer views in xibs and when one was open from a menu item, close another.我的解决方案是在 xibs 中使用许多 avplayer 视图,当一个从菜单项打开时,关闭另一个。

- (void)Visual02Menu:(id)sender {
         if (!visual02Window) {
         visual02Window = [[Visual02 alloc] initWithWindowNibName:@"Visual02"]; }
        [visual01Window close];
        [visual02Window showWindow:self];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM