Question

I'm trying to make a video player that can play various video format with ffmpeg and sdl2, and I need to display video frames inside a UIView. After looking into SDL api and its samples i couldnt find a way to do it. SDL use SDL_Renderer to render image in to a SDL_Window, which holds a reference to a UIWindow (the main UIWindow of the app), not a particular UIView.

Any suggestion?

Was it helpful?

Solution

hmm... thats a lot of ground to cover here but I'll try.

I suspect not to many devs besides us have done this.

First of all I don't know of any solutions that use sdl2, but its certainly possible with sdl 1.3 .

https://github.com/mooncatventures-group/RTSPPlay

Notice the app delegate , it creates a view controller that creates an sdl window and launches the player.

Notice the folder uikit, uikit is the portion of sdl that interfaces with sdl. The app delegate here can be modified, this one is set up to use two windows and swap between, but we also have used the following methods to swap views.

-(void) swapViews {
    UIWindow *windows = [[UIApplication sharedApplication] keyWindow];
    NSLog(@"the app has %d views ",[windows.subviews count]);
    //toggle_pause();
    UIView *view = [window.subviews objectAtIndex:0];
    [view removeFromSuperview];
    [windows addSubview:view];
}



-(void) swapViewsWithTransition {
    UIWindow *windows = [[UIApplication sharedApplication] keyWindow];
    UIView *firstView = [window.subviews objectAtIndex:0];
    UIView *secondView = [window.subviews objectAtIndex:1];       
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:([secondView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:firstView cache:YES];
    [firstView removeFromSuperview];
    [windows addSubview:firstView];
    [UIView commitAnimations];




}

Some time ago , I wrote a thread on this on the sdl forum here.

http://forums.libsdl.org/viewtopic.php?t=7352&sid=6b714337317597eaca026ae6be968b3e

There are some caveats with using these techniques

RTSPPlay can play almost any video you throw it well, but sdl event loops don't play to well with apple runloops, tableviews are especially troublesome, they tend to get sluggish, if you code an app with sdl limitations in mind like rtspplay you get a nice video player but adding to an existing app can be problematic.

There are examples of native apps in the same git. Working sdl can be a painful experience at times good luck

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top