Playing chunck of bytes into MPMoviePlayerController on iPhone - ios

My application is actually downloading a video I can easily read with MPMoviePlayerController. But now I have my video split and so on a segment form (meaning I receive a segment.init and then some other segments containing the video such as video_mp4_init.segment, video_mp4_0000.segment, video_mp4_0001.segment etc) in my bundle.
What I am looking for is some help about the way I need to read the bytes. So far I'm reading the same way I read a video:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"tos_mp4_media_0000" ofType:#"segment"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
A black screen launches then quit. I know MPMoviePlayer does not read .segment and I do guess this is not the way it should be done but I run out of ideas.
I'd find it a bit odd if MPMoviePlayer does not allow the reading of bytes but it might also be a problem. I can swap to another video reader if needed.
Any idea is welcome.
Edited for futher informations.

Related

buffer video before playing it on iphone

I'm doing some testing which during I would like to:
- Take a video that is in the app folder
- load that video to memory (buffer it)
- play the bufferd frames from the memory
All made on iPhone
Actually,
I would like to play a video from memory.
(I also want to load the video to memory by frames).
I hope it clear enough.
How can I accomplish this?
Tnx
EDIT:
Maybe I can point my question a little more..
I have a server that streams video via UDP (let's say that for the simuloation I'm using VLC to stream via UDP).
What do I have to do and implement in order to get the UDP stream from VLC and display it on the screen of my I device (of course i'm talking about writing code and not using VLC streamer :-) ).
Hope that's better and that I'll get some answers now.
Tnx
A video has to be buffered only if you receive the video from a server over internet via packets/Streams.
Else you can just play the video using below code:-
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"yourVideo" ofType:#"yourVideoType" inDirectory:#""]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[player view] setFrame:[self.view bounds]];
[self.view addSubview:[player view]];
[player play];
[player release];
You can implement the notification MPMoviePlayerLoadStateDidChangeNotification, if you are playing the videos after fetching over some data service.(GPRS,2G, Internet.)

iOS - Video Streaming, Prevent Video from being downloaded or saved locally

Is there any way to play Video Streaming via URL in iOS native App which can not be downloaded or saved locally. I want to let the user watch video but he should not be able to download or save video locally (via 3rd party downloader apps).
Is above case can be possible in MPMoviePlayerController, MPMoviePlayerViewController or WebViewController?
Any suggestion will be appreciated.
It is possible via MPMoviePlayerViewController.
NSURL *url = [NSURL URLWithString:yourLink];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];

MPMoviePlayerController for remote file on Amazon S3

My app allows videos to be displayed in UITableViewCells on iOS.
I'm currently storing my video files in Amazon S3 and utilizing Cloudfront. I got this code from the Apple docs:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
I have implemented this code pretty much exactly into my own app. For some reason, it does not seem to work for me. I think it may have something to do with not having JWPlayer installed in my S3 bucket.
My question is: In order to display a video in the app that allows playing while loading the remaining contents of the video in the background, do I need to have JWPlayer in my S3 bucket?...or is this unnecessary given the use of MPMoviePlayerController.
Thanks!
Well the problem is that the MPMoviePlayerController can't play that file because is not streamed. [[MPMoviePlayerController alloc] initWithContentURL: myURL]; expects a network stream, in your case is not a network stream. What you could do, is download the file and save it in your app documents files and play it from there.

MPMoviePlayerController is not responding to device volume controls

I'm working on a game that during the title sequence plays a video in the background using MPMoviePlayerController. I overlay my game controls over this (just a few textured UIButtons).
The video itself has no audio, but I'm playing sounds when I press buttons via OpenAL.
The Audio Session is set to "Ambient" and whenever the MPMoviePlayerController is not around it responds correctly to device's mute button and volume. But as soon as the video starts playing it blares out the sounds with no regard to the mute or volume settings.
Can anyone help me? Is the MPMoviePlayerController interfering with the AudioSession state?
Is there a way to stop this from happening. My movie has no sound in it so it shouldn't need to do that.
The MPMoviePlayerController uses the AVAudioPlayer shared instance. So you can literally set the volume of the MPMoviePlayerController and it will turn down your background music. However, a better way is to tell MPMoviePlayerController to not use the shared instance.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"intro" ofType:#"m4v"]];
self.player = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.player.movieSourceType = MPMovieSourceTypeFile;
**[self.player setUseApplicationAudioSession:FALSE];**

Play Multiple Videos from one page

Ok, so I am creating a basic iPad app that needs to play 4 videos. Videos need to be accessed from the same page.
I have one page/landing screen with an image that I have placed 4 Round Rec Buttons on. The MediaPlayer/MediaPlayer.h framework works perfectly, exactly what I want. But right now all four buttons play the same video, mainly because there is only one set of code but that is my problem. I assumed that repeating the code would allow me to replace the pathForResource:#"Beginning_Bumper" ofType:#"m4v" section of code but I get re-implimentation errors and the build fails. I've tried looking for other apps or tutorials online with no results. Also thought this question was my answer, but nothing there.
Here is the code I have, without duplication. So this code just plays one of the videos. Hopefully all of that makes sense, but feel free to ask more questions.
#import "Video_Presentation1ViewController.h"
#implementation Video_Presentation1ViewController
-(IBAction)playvideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Beginning_Bumper" ofType:#"m4v"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];playerController=nil;
}

Resources