Streaming Video again...
Monkey Targets Forums/iOS/Streaming Video again...
| ||
Hi, I am still trying to get video playing and have got this native code almost working: void MPlayerStreamVideo( String URL ) { NSString *videoURLString = URL.ToNSString(); NSURL *videoURL = [NSURL URLWithString:videoURLString]; MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; [moviePlayer prepareToPlay]; [moviePlayer play]; } Monkey Extern: Function MPlayerStreamVideo(Url$) It now compiles with error: Undefined symbols for architecture i386: "_OBJC_CLASS_$_MPMoviePlayerController", referenced from: objc-class-ref in main.o ld: symbol(s) not found for architecture i386 Can any iOS experts help?? Thanks. |
| ||
you'll need to link with the mediaplayer framework, add it to the xcode project. |
| ||
Thanks Adam, I had added #import <MediaPlayer/MediaPlayer.h> to my native code file but had not added the framework in Xcode. It now compiles without errors and runs, but nothing happens if I call MPlayerStreamVideo(Url$)... |
| ||
maybe you need to call [moviePlayer play]; in every OnRender? |
| ||
I figured it would just pop up the mediaplayer and start playing... maybe I need to open a new subview? |
| ||
maybe yes, maybe not. i am almost sure it won't auto play for you just by calling "play". at least ffmpeg doesn't do that. read docs for MPlayerStream and apply them to Monkey and you're done :) |
| ||
Ok, I am getting close now, this native code streams the video on the mojo view at the frame size specified, but I need to find a way to stop it or detect when its finished and release it, any help would be great?void MPlayerStreamVideo(String URL) { NSString *videoURLString = URL.ToNSString(); //NSString *filepath = @"http://www.coppercircle.co.uk/big-buck-bunny-clip.m4v"; NSURL *videoURL = [NSURL URLWithString:videoURLString]; MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; [moviePlayer.view setFrame:CGRectMake( 0, 0, 320, 220)]; [[[UIApplication sharedApplication] keyWindow] addSubview:moviePlayer.view]; [moviePlayer prepareToPlay]; [moviePlayer play]; } |
| ||
Well this streams the video fullscreen and shows the done button which closes it and returns to your app, just need to do the same in Android now.void MPlayerStreamVideo(String URL) { NSString *videoURLString = URL.ToNSString(); NSURL *videoURL = [NSURL URLWithString:videoURLString]; MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; [[[UIApplication sharedApplication] keyWindow] addSubview:moviePlayer.view]; moviePlayer.fullscreen = YES; [moviePlayer prepareToPlay]; [moviePlayer play]; } |
| ||
nice work, that is excellent news :) |
| ||
How did you make it close and return to your app? After I click done it stays on a black screen with the time and battery showing, rather than fullscreen monkey |
| ||
incase anyone wants to load the video from the data folder I quickly hacked this together from CopperCircle's code above:void MPlayerPlayVideo(String FILE) { NSString *videoString = FILE.ToNSString(); NSString *videoURL = [NSString stringWithFormat:@"data/%@", videoString ]; NSString *filepath = [[NSBundle mainBundle] pathForResource:videoURL ofType:@"m4v"]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; [[[UIApplication sharedApplication] keyWindow] addSubview:moviePlayer.view]; moviePlayer.fullscreen = YES; moviePlayer.shouldAutoplay = YES; [moviePlayer play]; } Any idea how to implement notifications to remove the movePlayer.view and dealloc once playback has finished? |
| ||
Hi, the fullscreen example does go back to the monkey screen for me but it should really release the movie. It needs to use notifications but I'm not sure how to get it to work:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; ...... - (void) moviePlayBackDidFinish:(NSNotification*)notification { MPMoviePlayerController *moviePlayer = [notification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) { [moviePlayer.view removeFromSuperview]; } [moviePlayer release]; } |
| ||
Anyone? |
| ||
I still can't get the notifications working for it to release the video, I really need this for a project I'm working on and could pay if someone could help? Thanks. |
| ||
Im still trying and getting closer, still don't really know what I'm doing in Objective C but this now plays video and auto rotates and goes back to the Monkey screen. but then the Monkey app does not respond? Not sure why the focus does not return... void MPlayerStreamVideo(String URL) { NSString *videoURLString = URL.ToNSString(); NSURL *videoURL = [NSURL URLWithString:videoURLString]; MPMoviePlayerViewController *movieVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL]autorelease]; UIViewController *view=app->appDelegate->viewController; [view presentMoviePlayerViewControllerAnimated:movieVC]; // Start playback [movieVC.moviePlayer prepareToPlay]; [movieVC.moviePlayer play]; } |
| ||
Hooray it works, I wad being stupid and forgot my app had suspended when video starts, just added this to my monkey code and all works. #MOJO_AUTO_SUSPEND_ENABLED="true" |
| ||
Damn, I was running the wrong Xcode code, it still doesn't respond after the video releases. The monkey is still running and can continue to draw/play audio just no touch response. |
| ||
That sounds exactly like the issue I had with Monkey and touches when I was integrating BFG lib. If you can, please send your project to Mark Sibly, as it will be something he can debug on. I could not send the full code to my game, as it was just to big. The newest Monkey should have a trick that makes touches alive, but it's a dirty trick, not solving core issue. And let us know which version of Monkey you are using. |
| ||
Hi anawiki, thanks for the reply, I was using Monkey v56 and the app would just not respond after playing a movie, I just tried Monkey v58 and now it crashes if there is a touch after playing the movie, so it is trying to respond to touches now. crashes in xcode under gxtkInput: for( int pid=0;pid<32;++pid ){ if( touches[pid] && touches[pid].view!=view ) touches[pid]=0; } My iOS code is still this: void MPlayerStreamVideo(String URL) { NSString *videoURLString = URL.ToNSString(); NSURL *videoURL = [NSURL URLWithString:videoURLString]; MPMoviePlayerViewController *movieVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL]autorelease]; UIViewController *view=app->appDelegate->viewController; [view presentMoviePlayerViewControllerAnimated:movieVC]; // Start playback [movieVC.moviePlayer prepareToPlay]; [movieVC.moviePlayer play]; } |
| ||
I tried the other night to get this working with notifications and did not get anything more working than what you have already posted. It would be awesome to have video functionality and it feels like its almost there! |
| ||
Did anything happen with this, is it possible yet? |
| ||
I got it working, but it was quite a few versions of Monkey ago, it may not work now. |
| ||
Would you be willing to share the working code? |
| ||
I don't have anytime at the moment but I will be getting SKN3 to make a new module soon to stream video on iOS and Android. I will release that to the community. |
| ||
That sounds awesome, thanks for the reply. :) |
| ||
I just tried and you can achieve the same thing using the webview module and opening a video URL. http://www.monkeycoder.co.nz/Community/posts.php?topic=5091#56818 |