diff --git a/ChromiumBasedEditors/lib/include/mac_cefviewmedia.h b/ChromiumBasedEditors/lib/include/mac_cefviewmedia.h index 5b0f0d00..28b61afe 100644 --- a/ChromiumBasedEditors/lib/include/mac_cefviewmedia.h +++ b/ChromiumBasedEditors/lib/include/mac_cefviewmedia.h @@ -5,6 +5,14 @@ #import +@interface NSMediaView : NSView +{ + NSView* m_pPlayerView; + NSRect m_oFrame; +} +- (void) setPlayerLayer:(AVPlayerLayer*)layer; +@end + class DESKTOP_DECL CCefViewMedia : public CCefViewWrapper { public: @@ -17,7 +25,7 @@ public: private: AVPlayer* m_pPlayer; - NSView* m_pMediaView; + NSMediaView* m_pMediaView; }; #endif // MAC_CEF_VIEW_MEDIA_H diff --git a/ChromiumBasedEditors/lib/src/mac_cefviewmedia.mm b/ChromiumBasedEditors/lib/src/mac_cefviewmedia.mm index a20f7d4e..828c9c4d 100644 --- a/ChromiumBasedEditors/lib/src/mac_cefviewmedia.mm +++ b/ChromiumBasedEditors/lib/src/mac_cefviewmedia.mm @@ -2,6 +2,33 @@ #import "../../../../core/DesktopEditor/common/Mac/NSString+StringUtils.h" +@implementation NSMediaView +- (instancetype)initWithFrame:(NSRect)frameRect +{ + self = [super initWithFrame:frameRect]; + if (self) + { + m_oFrame = NSMakeRect(0, 0, frameRect.size.width, frameRect.size.height); + m_pPlayerView = [[NSView alloc] initWithFrame:m_oFrame]; + [self addSubview:m_pPlayerView]; + } + return self; +} + +- (void)drawRect:(NSRect)dirtyRect +{ + // draw black background (by default it is transparent for AVPlayerLayer) + [[NSColor blackColor] setFill]; + NSRectFill(m_oFrame); + [super drawRect:dirtyRect]; +} + +- (void)setPlayerLayer:(AVPlayerLayer*)layer +{ + [m_pPlayerView setLayer:layer]; +} +@end + CCefViewMedia::CCefViewMedia(NSView* pView) : CCefViewWrapper(pView) { m_pPlayer = nil; @@ -22,8 +49,8 @@ void CCefViewMedia::OnMediaStart(NSEditorApi::CAscExternalMedia* data) m_pPlayer = [AVPlayer playerWithURL:url]; AVPlayerLayer* layer = [AVPlayerLayer playerLayerWithPlayer:m_pPlayer]; - m_pMediaView = [[NSView alloc] initWithFrame:NSMakeRect(data->get_BoundsX(), cef_height - data->get_BoundsH() - data->get_BoundsY(), data->get_BoundsW(), data->get_BoundsH())]; - [m_pMediaView setLayer:layer]; + m_pMediaView = [[NSMediaView alloc] initWithFrame:NSMakeRect(data->get_BoundsX(), cef_height - data->get_BoundsH() - data->get_BoundsY(), data->get_BoundsW(), data->get_BoundsH())]; + [m_pMediaView setPlayerLayer:layer]; [m_pParent addSubview:m_pMediaView positioned:NSWindowAbove relativeTo:nil];