Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 使用AVPlayer在OS X上播放全屏视频_Macos_Avfoundation_Avplayer - Fatal编程技术网

Macos 使用AVPlayer在OS X上播放全屏视频

Macos 使用AVPlayer在OS X上播放全屏视频,macos,avfoundation,avplayer,Macos,Avfoundation,Avplayer,我想知道使用AVPlayer在Mac全屏上捆绑播放视频的最佳方式是什么 我尝试了这个方法,只有在创建新的场景/ViewController,附加AVPlayerView,然后在viewDidLoad中加载文件时,它才会起作用 let url = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("wallaby", ofType:"m4v")) let videoPlayer = AVPlayer(URL: u

我想知道使用AVPlayer在Mac全屏上捆绑播放视频的最佳方式是什么

我尝试了这个方法,只有在创建新的场景/ViewController,附加AVPlayerView,然后在viewDidLoad中加载文件时,它才会起作用

    let url = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("wallaby", ofType:"m4v"))
    let videoPlayer = AVPlayer(URL: url)
    playerView.player = videoPlayer
    videoPlayer.play()
问题是:

此方法不会全屏显示 我看不到全屏显示的按钮 我所能做的最好是显示一个全屏窗口:

self.view.frame.size = NSScreen.mainScreen().frame.size

感谢您提供一些示例代码的提示或指针

AVPlayerView类包括showsFullScreenToggleButton属性。

AVPlayerView类包括showsFullScreenToggleButton属性。

我在AVPlayerView中也遇到了这个问题。如果我像这样启用全屏按钮:

self.playerView.showsFullScreenToggleButton = YES;
我点击全屏按钮,视频进入全屏,但是,应用程序不接受任何按键输入,您无法激活Mission Montrol、LaunchPad等。这是一种非常糟糕的用户体验,我相信如果您向Mac app Store提交这样的应用程序,它将被拒绝。我也试着让我的AVPlayerView成为第一反应者,但是没有用

解决方案 所以,我看了QuickTime Player如何在全屏播放视频方面发挥作用。我注意到,它没有一个按钮,全屏的球员控制。它处理全屏的方式是,当用户单击窗口的全屏控件时,它会重新调整窗口的大小,如果我没有弄错的话,可以使用AVPlayerView或苹果正在使用的任何东西。要实现类似的功能,请执行以下操作:

//The window that contains your AVPlayerView set the delegate
 [self.window setDelegate:self];


//So you can respond to these notifications

- (void)windowDidEnterFullScreen:(NSNotification *)notification{
        // wait a bit
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                if (self.playerView.isReadyForDisplay == YES) {

        //Make sure the playerView is ready for display

        //Set the playerView to the screen's current frame (Very Important!)
         [self.playerView setFrame:[[NSScreen mainScreen] frame]];

        //Do other UI related things here e.g hide elements e.t.c

        }

        });
        }

- (void)windowWillExitFullScreen:(NSNotification *)notification{
//Do other UI related things here e.g show elements e.t.c

}

//If you have a ToolBar in your application do this:

- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
    return (NSApplicationPresentationFullScreen |
            NSApplicationPresentationHideDock |
            NSApplicationPresentationAutoHideMenuBar |
            NSApplicationPresentationAutoHideToolbar);
}

// To determine if the window is in fullscreen e.g. if the application opened/restored in a fullscreen state the windowDidEnterFullScreen will not be called. So you need to do this:

- (BOOL) isFullScreenMode {
    NSApplicationPresentationOptions opts = [[NSApplication sharedApplication ] presentationOptions];
    if ( opts & NSApplicationPresentationFullScreen) {
        return YES;
    }
    return NO;
}
结论
我希望这能回答你的问题。另外,我认为这是苹果方面的一个缺陷,所以我明天将提交一份缺陷报告。

我在AVPlayerView上也遇到了这个问题。如果我像这样启用全屏按钮:

self.playerView.showsFullScreenToggleButton = YES;
我点击全屏按钮,视频进入全屏,但是,应用程序不接受任何按键输入,您无法激活Mission Montrol、LaunchPad等。这是一种非常糟糕的用户体验,我相信如果您向Mac app Store提交这样的应用程序,它将被拒绝。我也试着让我的AVPlayerView成为第一反应者,但是没有用

解决方案 所以,我看了QuickTime Player如何在全屏播放视频方面发挥作用。我注意到,它没有一个按钮,全屏的球员控制。它处理全屏的方式是,当用户单击窗口的全屏控件时,它会重新调整窗口的大小,如果我没有弄错的话,可以使用AVPlayerView或苹果正在使用的任何东西。要实现类似的功能,请执行以下操作:

//The window that contains your AVPlayerView set the delegate
 [self.window setDelegate:self];


//So you can respond to these notifications

- (void)windowDidEnterFullScreen:(NSNotification *)notification{
        // wait a bit
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                if (self.playerView.isReadyForDisplay == YES) {

        //Make sure the playerView is ready for display

        //Set the playerView to the screen's current frame (Very Important!)
         [self.playerView setFrame:[[NSScreen mainScreen] frame]];

        //Do other UI related things here e.g hide elements e.t.c

        }

        });
        }

- (void)windowWillExitFullScreen:(NSNotification *)notification{
//Do other UI related things here e.g show elements e.t.c

}

//If you have a ToolBar in your application do this:

- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
    return (NSApplicationPresentationFullScreen |
            NSApplicationPresentationHideDock |
            NSApplicationPresentationAutoHideMenuBar |
            NSApplicationPresentationAutoHideToolbar);
}

// To determine if the window is in fullscreen e.g. if the application opened/restored in a fullscreen state the windowDidEnterFullScreen will not be called. So you need to do this:

- (BOOL) isFullScreenMode {
    NSApplicationPresentationOptions opts = [[NSApplication sharedApplication ] presentationOptions];
    if ( opts & NSApplicationPresentationFullScreen) {
        return YES;
    }
    return NO;
}
结论 我希望这能回答你的问题。另外,我认为这是苹果的一个缺陷,所以我明天将提交一份缺陷报告。

在Swift中:

迅速:


我发现为什么全屏模式下的切换按钮不可单击,因为您可能会显示一个视图而不是窗口。例如,您使用按钮和视图之间的序列图像板序列,您应该将按钮链接到视图的父窗口。

我发现为什么全屏模式下的切换按钮不可单击,因为您可能会显示一个视图而不是窗口,例如,您在按钮和视图之间使用序列图像板序列,所以您应该将按钮链接到视图的父窗口。

谢谢。我在最新的优胜美地上试过这个,一旦你点击全屏切换按钮进入全屏,屏幕就不能再操作了,点击任何地方只会发出嘟嘟声。退出应用程序的唯一方法是使用Command-Q。你没有看到控制栏上的“恢复正常大小”按钮吗?一旦我全屏播放,切换按钮实际上整个屏幕都不可点击,就像它们不再是最前面的窗口一样。我用的是约塞米蒂,不知道我做错了什么,我需要做最前面的窗口还是其他什么?如果你愿意,请给我发送你的xcode项目,我会在Mavericksk上试用。谢谢Michele的建议。我正在为约塞米蒂开发应用程序,所以它是否适用于小牛并不重要。谢谢。我在最新的优胜美地上试过这个,一旦你点击全屏切换按钮进入全屏,屏幕就不能再操作了,点击任何地方只会发出嘟嘟声。退出应用程序的唯一方法是使用Command-Q。你没有看到控制栏上的“恢复正常大小”按钮吗?一旦我全屏播放,切换按钮实际上整个屏幕都不可点击,就像它们不再是最前面的窗口一样。我用的是约塞米蒂,不知道我做错了什么,我需要做最前面的窗口还是其他什么?如果你愿意,请给我发送你的xcode项目,我会在Mavericksk上试用。谢谢Michele的建议。我正在为约塞米蒂开发应用程序,因此它是否能在Mavericks上运行并不重要。OP要求使用OS X,此代码仅适用于iOS imports UIKit。OP要求使用OS X,此代码仅适用于iOS imports UIKit。