我正在尝试使用 Mac OS X 编写一个简单的 DVD 播放器DVDPlayback.framework
。我可以让 DVD 在窗口内播放,但最终我希望它作为全屏应用程序运行。
我在播放 DVD 时难以添加子视图来显示媒体控件(暂停/播放、进度滑块滚动电影、更改章节等)。
似乎如果我NSView
在 DVD 框架使用的窗口中创建子视图 ( ),它似乎总是落后于 DVD 内容,即使我告诉NSView
它位于最顶层。
这是简化的代码,它只是尝试在窗口的一个区域内创建一个白色的子视图:
(我在 10.6 和 10.7 上尝试过代码,结果相同)。
const BOOL PLAY_DVD = YES;
@interface ControlsView : NSView {
}
@end
@implementation ControlsView
- (void)drawRect:(NSRect)rect {
[[NSColor whiteColor] set];
NSRectFill(rect);
}
@end
@implementation AppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSView *view = self.window.contentView;
if (PLAY_DVD) {
NSLog(@"%@ Playing DVD video", [self class]);
// Register error handler
OSStatus err;
err = DVDInitialize();
if (err != noErr) {
NSLog(@"DVDInitialise failed with error code %d", err);
[NSApp terminate:self];
}
// Set window to be the main window
err = DVDSetVideoWindowID([self.window windowNumber]);
// Set the display...
CGDirectDisplayID display = (CGDirectDisplayID) [[[[self.window screen] deviceDescription] valueForKey:@"NSScreenNumber"] intValue];
Boolean isSupported;
err = DVDSwitchToDisplay(display, &isSupported);
// Set video bounds
NSRect frame = [self.window frame];
CGRect rect = CGRectMake(0, 0, frame.size.width, frame.size.height);
err = DVDSetVideoCGBounds(&rect);
FSRef ref;
DVDOpenMediaFileWithURL([NSURL URLWithString:@"file:///Path/to/my/TestDVD/VIDEO_TS"]);
DVDOpenMediaFile(&ref);
DVDPlay();
}
// Attempt to add a subview to show the controls...
ControlsView *controls = [[ControlsView alloc] initWithFrame:NSMakeRect(20, 20, 100, 50)];
[view addSubview:controls positioned:NSWindowAbove relativeTo:nil];
}
@end
如果PLAY_DVD
是NO
,则正确呈现子视图(我可以创建其他子视图并显示顺序正确)。
如果PLAY_DVD
是YES
,则媒体开始播放,但子视图永远不可见,因为它似乎总是落后于视频。
我能找到的唯一 DVD 播放示例在第二个窗口中有控件,但对于全屏应用程序,我希望控件成为全屏视图的一部分并淡入/淡出在需要的时候。
有谁知道如何最好地做到这一点?我的全屏控件是否必须位于浮动在全屏窗口上方的单独窗口中?我找不到在同一个窗口中具有控件和 DVD 播放的示例。
在此先感谢您的帮助!