HTTP Live Streaming in iPhone - iphone

I am using MPMoviePlayerController to stream http video files from web.
But am getting error and the video is not streaming.
Can I get any help for this?
-(IBAction)play
{
NSString *urlString = [NSString stringWithFormat:#"<html><head><title>HTTP Live Streaming Example</title></head><body><video src=http link"];
NSURL *url = [NSURL fileURLWithPath:urlString];
_mpMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_mpMoviePlayer];
[self.view addSubview:_mpMoviePlayer.view];
[_mpMoviePlayer release];
}
This is my code and I am not able to get the streaming video.

Related

MPMoviePlayerController Endless Loading

I'm trying to play an MP4 file with the MPMoviePlayerController (also tried two m4v files, same problem), and finally got the video player to come up, but it just stays loading. Here's my code, executed on a button press:
NSString *videoFile = [[NSBundle mainBundle] pathForResource:#"attn8" ofType:#"mp4" inDirectory:#""];
NSURL *url = [NSURL fileURLWithPath:videoFile isDirectory:NO];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.movieSourceType = MPMovieSourceTypeFile;
//put on a whim from another answer, made no difference
[self.view addSubview:[player view]];
player.fullscreen = true;
[player prepareToPlay];
[player play];

how to play video from htp url in iphone app

I want to play the video from url in iphone app but it does not play in the app i am using following code
-(IBAction)play
{
NSString*videoFilepath=#"http://myserver.com.pk/Specticle_Revision_v1.mov";
NSLog(#"Filepath is: %#", videoFilepath);
NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath];
MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie];
[movie play];
}
Do this:
NSURL *url = [NSURL URLWithString:#"http://myserver.com.pk/Specticle_Revision_v1.mov"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mp];
[mp release];
Looks like this:
NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath];
Is your problem. Your "http://" - style URL is not a file URL. File URL's (on the local device / file system) begin with "file:///".
Try:
NSURL * videoURL = [NSURL URLWithString: videoFilepath];
and see if that works better.

Play video stored in NSData

I am trying to play a video that is stored in an NSData object. I save the file to my applications temp folder and then try to play it, but all I get is a black screen. I can later browse to that folder and play the file, so I know that the file gets written and is supported.
This is my code:
NSString *urlString = [NSTemporaryDirectory() stringByAppendingPathComponent:#"test.m4v"];
NSURL *url = [[NSURL alloc] initWithString:urlString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: url];
[moviePlayer prepareToPlay];
moviePlayer.view setFrame: self.view.bounds];
[self.view addSubview: moviePlayer.view];
[moviePlayer play];
The only thing I can think of is that it takes some time for the file to get written, and the player tries to access it before it is done. Is that possible, and if so, how do I fix it?
When working with files you should tell the NSURL that the URL should point to a
file:
NSString *urlString = [NSTemporaryDirectory() stringByAppendingPathComponent:#"test.m4v"];
NSURL *url = [NSURL fileURLWithPath:urlString];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: url];
[moviePlayer prepareToPlay];
moviePlayer.view setFrame: self.view.bounds];
[self.view addSubview: moviePlayer.view];
[moviePlayer play];

iPhone - Resuming background music after playing movie

I'm playing iTunes music in the background.
I started my app which plays "Video" using the following code:
NSString* videoPath = [[NSBundle mainBundle] pathForResource:#"video" ofType:#"m4v"];
if (player) {
[player release];
player = nil;
}
player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]];
[self presentModalViewController:player animated:YES];
I'm setting the audio session as follows:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error:nil];
When my video starts playing, iPod music playing in the background will be stopped.
How can I resume the background music when my video completes?
This kind of option to continue must from ipod is not possible.
Use notifications
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
- (void) moviePlayBackDidFinish {
// resume your AVAudioSession
}

Play Videos in MPMoviePlayerController from a URL?

i am trying to play a video from a Url with help of MPMovieplayer which loads it in the Quicktime player while i want the video to play in my application only(no background mode)?? how can i achieve that?? will playing the video in a UIWebview instead of MPMoviePlayer work??
Also when QuickTime Player loads only Audio plays and no video is displayed?? i am using the following code
NSString *videoFilepath = #"http://www.migital.com/Hemant/1.3gp";
NSURL *videoURL = [NSURL URLWithString:videoFilepath ];
MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
[self presentMoviePlayerViewControllerAnimated:movie];
you have to add movie.view to your view
web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
NSString *urlAddress = #"HTTP://";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[web loadRequest:requestObj];