objective-c - Change AVPlayer Video MacOS Objective-C Cocoa
问题描述
For MacOS, not iOS. I am playing a video in an AVPlayerView in an XIB. 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.
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. 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.
解决方案
My solution was to use many avplayer views in xibs and when one was open from a menu item, close another.
- (void)Visual02Menu:(id)sender {
if (!visual02Window) {
visual02Window = [[Visual02 alloc] initWithWindowNibName:@"Visual02"]; }
[visual01Window close];
[visual02Window showWindow:self];
推荐阅读
- javascript - 再次将字符串 React Component 转换为 jsx
- go - go micro 在运行 make build 时给了我这种错误
- asp.net - 用于创建启动项目的 dotnet 命令
- python - 如何通过蓝牙连接 React Native 应用程序和树莓派?
- regex - 没有html标签的url的正则表达式
- c# - 如何通过在 ASP.NET Core 中调用外部 API 在启动期间在每个应用程序生命周期内初始化一次属性或变量?
- laravel - Laravel 计划对 Elastic Beantstalk CRON 作业没有影响
- spring-boot - spring批量compositeItemWriter块自定义
- google-cloud-platform - 使用 Google Cloud 部署管理器部署防火墙资源时如何解决 ResourceErrorCode:400
- python - 如何使用 zed 立体相机生成视差图?