Issue Playing sound from url - iphone

I am making an Iphone app which have requirement to play sound in a loop. The sound will come from HTTP links like follows:
Link 1
Link 2
Link 3
Link 4
Link 5
Link 6
Link 7
Link 8
Actually there are three button loop,play all and stop. I am able to do play once click all and loop but When i click other button app will crash.How can i solve this problem.My code is below resultArrayFinal is a globle array where all above sound link store.
-(void)replayVedio
{
DataClass *obj=[DataClass getInstance];
NSURL *url = [NSURL URLWithString:obj.soundInfo];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleDefault];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
if(_globle==1)
{
[self replayAudio];
}
else if(_globle==2)
{
DataClass *obj=[DataClass getInstance];
obj.soundInfo=[resultArrayFinal objectAtIndex:count++];
if (count==[resultArrayFinal count])
count=0;
[self replayAudio];
}
}
Thanks.

Related

Video from web cam is not streaming in iPhone/Objective c

I am trying this code but it shows a still image, and not proper video streaming. However it shows the video, but only for some time.
[reykjavikurtjorn loadRequest:[NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://213.167.154.114/mila/_definst_/tjornin.stream/playlist.m3u8"]]];
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:#"http://www.domain.com/myVideo.mp4"];
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mpvc];
and the delegate
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player respondsToSelector:#selector(setFullscreen:animated:)]) {
[player.view removeFromSuperview];
}

streaming videos on iPhone

I want to stream large videos from ftp in iPhone. The video are in size more then 500 MB. I have never done streaming so have no idea about it. I have checked live streaming guide from Apple but it does not provide any help regarding coding in iPhone. Can some one help me what exactly I have to do in iPhone coding? So far I have done following:
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"http://www.defencecourse.com/digital-reproductions/yellow-belt.mp4"]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mpvc];
[mpvc release];
Is this coding enough to play a streaming video?
I have a guy who prepare videos for me what should I exactly ask him to do with videos on the server? Should I ask him just to split videos on server or something else?
Can Someone please suggest me best way to forward?
Regards
Pankaj
Check these tutorials AVFoundation Tutorials and read out the Apple's AVFoundation Framework programming guide here
AVFoundation Framework is much more powerful.
Hi You have to do following things on iphone side ...
-(void) btnClose_clicked {
[appDelegate.navShowController dismissModalViewControllerAnimated:YES];
}
-(IBAction) btnPlay_clicked {
// NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"3idiots.mov" ofType:nil];
// NSURL *url =[NSURL fileURLWithPath:urlStr];
NSURL *url = [[NSURL alloc] initWithString:[self.DiscAnsDetail objectForKey:#"product_video"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
} else {
// Use the old 2.0 style API
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// If the moviePlayer.view was added to the view, it needs to be removed
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
[moviePlayer release];
}

Play 2 videos from url one after another

In my application i want to play 2 url videos one after another.
This is my code:
`- (void)viewDidLoad {
NSLog(#"viewDidLoad");
player = [[MPMoviePlayerController alloc] initWithContentURL:[self movieURL]];
[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player play];
[super vieDidLoad];
}
- (NSURL *)movieURL {
return [NSURL URLWithString: #"https://s3.amazonaws.com/adplayer/colgate.mp4"];//First video url after this video complete.I want to play the next url video.
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(#"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player autorelease];
}
`
After one url video completed i want to play the next url video.
please anyone help me.
I have store the url's in array like this,
array=[[NSArray alloc] initWithObjects:#"https://s3.amazonaws.com/adplayer/colgate.mp4",#"https://s3.amazonaws.com/ventuno-platform-flv-sep2010/happy_family.mp4",nil];
Then how can i retrive the url in - (void) movieFinishedCallback:(NSNotification*) aNotification {
}method.please give me guidance in this.
I a have not tested it, but is should work, You might need it modify it little bit. At least, you now have an idea, how this can be done
-(void)viewDidLoad
{
[self initializPlayer];
}
static int i;
-(void)initializPlayer
{
if(i<=[arrMovieURL count])
i +=1;
else {
i = 0;
}
if(player)
{
[player release];
player = nil;
}
player = [[MPMoviePlayerController alloc] initWithContentURL:[arrMovieURL objectAtIndex:i]];
[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(#"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
//calling again to play the next video
[self initializPlayer];
}

Video Clip does not play correctly

I am trying to play a video in one of my screens. It seems to run but when the file opens, the fullscreen loads up and closes right after. The video is a few seconds long, and is m4v format. I added the framework and imported the class. How can I make it so that the video plays properly?
My header:
-(IBAction)playMedia:(id)sender {
NSString *movieFile;
MPMoviePlayerController *moviePlayer;
movieFile = [[NSBundle mainBundle]
pathForResource:#"movie" ofType:#"m4v"];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL: [NSURL fileURLWithPath: movieFile]];
[moviePlayer.view setFrame:CGRectMake(145.0, 20.0, 155.0 , 100.0)];
[self.view addSubview:moviePlayer.view ];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playMediaFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer play];
if ([toggleFullscreen isOn]) {
[moviePlayer setFullscreen:YES animated:YES];
}
}
My implementation file is:
-(void)playMediaFinished: (NSNotification*)theNotfication {
MPMoviePlayerController *moviePlayer=[theNotfication object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
}
thanks

MPMoviePlayer-Notification doesn´t get called

HI,
i want to play a movie using MPMoviePlayerViewController and listen to a MPMoviePlayerPlaybackDidFinishNotification, but it doesn´t get called. Any ideas on that?
Would be helpful to get any hints on that.. Thanks you
Here´s my code:
NSString *url = [[NSBundle mainBundle] pathForResource:[sender contentName] ofType:#"m4v"];
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer play];
}
- (void) moviePlayBackComplete:(NSNotification*) notification {
NSLog(#"moviePlayBackComplete complete");
MPMoviePlayerController* moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[self dismissMoviePlayerViewControllerAnimated];
[moviePlayerController release];
}
You're trying to get notifications from a MPMovePlayerViewController but I'm pretty sure only MPMoviePlayerController provides them. Try and change your notification setup
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];