Fix black background

This commit is contained in:
Mikhail Lobotskiy
2024-03-11 18:07:35 +04:00
parent 5f64794992
commit 65dc32b11f
2 changed files with 38 additions and 3 deletions

View File

@ -5,6 +5,14 @@
#import <AVFoundation/AVFoundation.h>
@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

View File

@ -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];