3

I would like to play a video with a transparent background. The only thing is that all the information I found on the internet is "how to make the video background transparent", but the background of my video is already transparent, now I need to make the background of the player transparent. How do I do that? I tried this:

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"New Project 5" ofType:@"m4v"];
NSLog(@"%@",resourcePath);
NSURL *url = [NSURL fileURLWithPath:resourcePath];
NSLog(@"%@",url);

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

moviePlayer.shouldAutoplay=YES;
moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayer setFullscreen:NO animated:YES];
[self.view addSubview:moviePlayer.view];

moviePlayer.view.frame = CGRectMake(200, 600, 400, 300);

[moviePlayer play];

moviePlayer.view.backgroundColor = [UIColor clearColor];
for(UIView *aSubView in moviePlayer.view.subviews) {
    aSubView.backgroundColor = [UIColor clearColor];
}

But it doesn't work. It displays a black background.

Alessandro
  • 4,000
  • 12
  • 63
  • 131
  • `UIView` has the `opaque` property that renders transparent as black by default for performance reasons. This was relevant with old iPhones, and the default value is YES. Try setting it to NO on the movie player (and possibly the subviews as well) – FeifanZ May 08 '13 at 18:28
  • [iPhone SDK - How to play a video with transparency?][1] [1]: http://stackoverflow.com/questions/1401517/iphone-sdk-how-to-play-a-video-with-transparency – Masa May 08 '13 at 18:35
  • @Masa that tells me how to make the background transparent, not how to make the video player transparent – Alessandro May 08 '13 at 19:00

1 Answers1

3

Here is a link with a real solution to this problem playing-movies-with-an-alpha-channel-on-the-ipad. Her blog post is talking about video on the iPad, but the same library with alpha channel support also works on iPhone. It is also possible to encode to h.264 with alpha channel support using the method described in the blog post comments.

MoDJ
  • 4,309
  • 2
  • 30
  • 65
  • MoDJ's library needs a commercial license, has rather involved extra steps and has not that great performance (extracting 7z, extra video track, etc) Here is a solution using free open source library, works entirely on the GPU (great performance even with big videos) and requires only two things: - Transparent image (either PNG or in code) - Instead of a transparent, a green background for the video http://stackoverflow.com/questions/33244347/video-with-gpuimagechromakeyfilter-has-tint-when-played-in-transparent-gpuimagev/33255662 – Морт Oct 21 '15 at 09:35
  • A point by point comparison that shows actual results from a green screen vs alpha channel comparison is available. http://www.modejong.com/blog/post18_green_screen/ – MoDJ Dec 02 '15 at 23:32