【问题标题】:Change AVPlayer Video MacOS Objective-C Cocoa更改 AVPlayer 视频 MacOS Objective-C Cocoa
【发布时间】:2020-05-21 12:14:03
【问题描述】:

适用于 MacOS,而不是 iOS。我在 XIB 的 AVPlayerView 中播放视频。只是尝试视频播放。我希望能够从文件菜单中选择一个选项(例如文件/视频/视频 1、视频 2、视频 3 等),并在我选择菜单项时更改 XIB 中当前正在播放的视频。

目前我正在使用它来播放视频:

- (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];
    }
}

并循环播放视频:

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

但我想通过选择菜单按钮来动态更改 XIB 中正在播放的视频。任何想法如何做到这一点?我听说 AVPlayerQueue 可能适用于这种事情,但我很新,无法在 MacOS 上运行。

【问题讨论】:

    标签: objective-c swift xcode macos cocoa


    【解决方案1】:

    我的解决方案是在 xibs 中使用许多 avplayer 视图,当一个从菜单项打开时,关闭另一个。

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

    【讨论】:

      猜你喜欢
      • 2011-06-17
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2019-01-26
      • 1970-01-01
      • 2011-01-05
      • 2011-09-13
      相关资源
      最近更新 更多