Add black backround in more simple way

This commit is contained in:
Mikhail Lobotskiy
2024-03-11 18:42:00 +04:00
parent 65dc32b11f
commit d159b39e4e
2 changed files with 4 additions and 38 deletions

View File

@ -5,14 +5,6 @@
#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:
@ -25,7 +17,7 @@ public:
private:
AVPlayer* m_pPlayer;
NSMediaView* m_pMediaView;
NSView* m_pMediaView;
};
#endif // MAC_CEF_VIEW_MEDIA_H

View File

@ -2,33 +2,6 @@
#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;
@ -48,9 +21,10 @@ void CCefViewMedia::OnMediaStart(NSEditorApi::CAscExternalMedia* data)
{
m_pPlayer = [AVPlayer playerWithURL:url];
AVPlayerLayer* layer = [AVPlayerLayer playerLayerWithPlayer:m_pPlayer];
[layer setBackgroundColor:CGColorCreateGenericRGB(0, 0, 0, 1.0)];
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_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_pParent addSubview:m_pMediaView positioned:NSWindowAbove relativeTo:nil];