【发布时间】: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