Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AVPlayer to view transparent video

Tags:

ios

I am trying to view a video witch has an alpha channel (the background is transparent). The only problem is that I don't seem to get how to make the background of the player transparent. I know I have to use AVplayer, but I can't access it's .view property. How can I add it to the subview and add a layer?

NSString *path = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath],   @"/New Project 5.m4v"];

NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

moviePlayer = [[AVPlayer alloc] initWithURL:filePath];

AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:moviePlayer];
self.playerLayer.frame = self.view.bounds;

moviePlayer.view.alpha = 0.3;
[moviePlayer.layer addSublayer:playerLayer];

[moviePlayer play];
like image 289
Alessandro Avatar asked Oct 31 '25 00:10

Alessandro


1 Answers

The iOS SDK does not properly support alpha channel video playback. That applies for AVFramework as well as the MediaPlayer Framework. Video material that contains an alpha channel will not work as you expect it to when using Apple's API.

And as you actually show within your code, AVPlayer does not use a UIView as its surface for playing videos but a subclass of CALayer, AVLayer.

You will need to rethink your application design or chose a different playback SDK.

like image 154
Till Avatar answered Nov 03 '25 15:11

Till



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!