NSInvalidArgumentException [NSURL length] url video record iphone - iphone

I save a video via iphone database application,the url where i'm recording the video is:
file://localhost/private/var/mobile/Applications/0DB3ABFC-1630-44FF-8506-4B08E3CB2C85/tmp/capture-T0x2591d0.tmp.00fEdr/capturedvideo.MOV
However, when I try to read the video via MediaPlayer it always crashes...
sample code:
NSString *frameName = [info objectForKey:#"UIImagePickerControllerMediaURL"];
NSURL *url = [NSURL URLWithString:frameName];
videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0, 0, 320, 419);
[videoPlayer play];
Thank you in advance.

Looks like the contents of [info objectForKey:#"UIImagePickerControllerMediaURL"] is not valid.
If it is valid, try fileURLWithPath rather then urlWithString.

Related

play video using url ios 6

I am struggling to play a video which is a url of the video file on a server. I have a view in which I display url from the web service. When I click the url(contained in a table cell) I want that a new view should appear with movie player on it playing the video. I have tried MPMoviePlayerViewController and also MPMoviePlayerController and various combinations of the two but I could not play the video on simulator. Currently I don't have a device so please consider simulator as well as device while answering. Currently i am using:
NSURL *url = [NSURL fileURLWithPath:filePath];
self.player= [[ MPMoviePlayerViewController alloc] initWithContentURL:url];
//self.player.navigationController.navigationBar.hidden = YES;
[self.player.moviePlayer prepareToPlay];
//self.player.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
self.player.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.player.moviePlayer.fullscreen = NO;
[self presentModalViewController:self.player animated:NO];
[self.player.moviePlayer play];
filepath is a nsstring containing the video url.
Replace your this line : NSURL *url = [NSURL fileURLWithPath:filePath];
with this: NSURL *url=[NSURL URLWithString:filePath]; & then try.
My Code I am using MPMOVIEPLAYERVIEWCONTROLLER:
NSData *geturl = [[videoparsing objectAtIndex:btntag]objectForKey:#"iurl"];
myString = [[NSString alloc] initWithData:geturl encoding:NSASCIIStringEncoding];
NSLog(#"myString..%#",myString);
NSURL *fileURL=[NSURL URLWithString:myString];
NSLog(#"fileURL..%#",fileURL);
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.moviePlayer.shouldAutoplay=YES;
[moviePlayerController.moviePlayer play];
If video file is on server then
NSURL *url=[NSURL URLWithString:filePath];
other should be change movieSourceType to MPMovieSourceTypeStreaming :
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
Also
self.player.moviePlayer.fullscreen = YES;
EDIT : Add :
self.player.moviePlayer.shouldAutoplay=YES;
remove :
[self.player.moviePlayer play];

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: initWithContentURL not playing the video

I have a .mp4 video url in my server and trying to play by using the following code. But it doesn't do any actions when click on play button. I'm trying to test on iPhone 4.0 simulator or iPod 4.1 device. Is there anything wrong here (or) can't it work on iOS 4.0 or 4.1?
NSURL *url = [NSURL fileURLWithPath:encodedURL];
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[self.view addSubview:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0, 0, 320, 480);
[videoPlayer play];
Please advise!
Encode function:
NSString *newString = [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR("?#[]#!$ &'()*+,;=\"<>%{}|^~`"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];
If the file is on a server than the line:
NSURL *url = [NSURL fileURLWithPath:encodedURL];
should be:
NSURL *url = [NSURL URLWithString:encodedURL];
You should also double check that the string encodedURL is correct by NSlog to your console.

Get an audio stream from URI and play it on iPhone

I would like to get an audio stream from URL and play it on iPhone. Unfortunately, there is only C# example of how to play that stream, but I need a realization on Objective C in iPhone frameworks. I have tried my self to use different audio frameworks but it was all unsuccessful. This is what in C#:
response = httpWebRequest.GetResponse();
using (Stream stream = response.GetResponseStream())
{
using (SoundPlayer player = new SoundPlayer(stream))
{
player.PlaySync();
}
}
What should I do in objective C to get a stream audio from that url? In that URL I don't have an mp3 file or something, I just get a stream. Probably I must somehow download that stream to an iPhone audio file and then play it to get rid of lags.
I tried this:
AVPlayer *player = [AVPlayer playerWithURL:url];
[player play];
And this:
AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL: url error:nil];
[theAudio setVolume :0.50]; //setting the volume
[theAudio play];
Neither worked.
I have tested my url, it works well in browser.
This is the code that worked:
NSData *_objectData = [NSData dataWithContentsOfURL:url];
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0f;
[audioPlayer prepareToPlay];
if (audioPlayer == nil)
NSLog(#"%#", [error description]);
else
[audioPlayer play];
NSString* resourcePath = url; //your url
NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]];
NSError *error;
app.audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
app.audioPlayer.numberOfLoops = 0;
app.audioPlayer.volume = 1.0f;
[app.audioPlayer prepareToPlay];
if (app.audioPlayer == nil)
NSLog(#"%#", [error description]);
else
[app.audioPlayer play];
Hey I faced this problem of audio streaming for a radio application. I had searched for the answers and they did not work. AVAudioPlayer is not the class to be used here. Downloading the contents of URL using NSData object is not the solution either as it downloads the contents then the code further executes. It is similar to downloading a mp3 and then playing it locally on a player.
[NSData dataWithContentsOfURL:[NSURL URLWithString:resourcePath]]; //Downloads the contents of the url and in case of radio the url's content is unlimited. The program gets frozen on executing this.
Instead use AVPlayer class.
This code worked in my radio application
AVPlayer *objAVPlayer = [[AVPlayer alloc] initWithURL:url];
[objAVPlayer play];
This code does not download the contents at the url but it plays the stream as it is received.
Look into the AVPlayer class, part of the AVFoundation framework... this is the objective-c (iOS) class you use for streaming audio.
MPMoviePlayerController *player;
player = [[MPMoviePlayerController alloc] init] ;
player.view.frame = CGRectMake(0, 0, 0, 0);
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview: [wikiMusicPlayer view]];
NSString *address = Your URL;
address = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:address];
[wikiMusicPlayer setContentURL:url];
[wikiMusicPlayer prepareToPlay];
[wikiMusicPlayer setShouldAutoplay: NO];
[wikiMusicPlayer play];

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];