This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Play YouTube videos with MPMoviePlayerController instead of UIWebView
I am trying to play video from a youtube url and once mpmovieplayer is launched, it is been closed instantly. How to play video from youtube url? note that I am using iOS5. Thanks.
- (IBAction)video1 {
//NSBundle *bundle = [NSBundle mainBundle];
//NSString *moviePath =[bundle pathForResource:#"" ofType:#"mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:#"http://www.youtube.com/testVideo"];
MPMoviePlayerController *daMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
daMovie.scalingMode = MPMovieScalingModeAspectFill;
[daMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
YouTube recommends you use the native YouTube-app, see this link for more info on that: http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html
Otherwise, check out this question on StackOverflow: Play YouTube videos with MPMoviePlayerController instead of UIWebView
Related
I am using following code to show video file in initial state.But when i launch app it start playing without giving me option to play.how i can achieve that
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"En_annan_resa_Master_ENG_PC" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
movie_obj = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[movie_obj.view setFrame:CGRectMake(1024*i, 0, 1024, 748)];
movie_obj.scalingMode=MPMovieScalingModeAspectFit;
[self.scrollView addSubview:movie_obj.view];
[movie_obj prepareToPlay];
I am expecting when i launch app it show mw video view and show control to play do not play automatically.
thanks for your help
check below answer
https://stackoverflow.com/a/15701076/1713478
just replace NO to En_annan_resa_Master_ENG_PC
try this your problem will solve
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Video file formats supported in iPhone
I Was Wondering which formats are ok to be inside an iPhone app, there is a view and I want to put this video there to start automatically...
This code should add a MPMoviePlayerController to your view and automatically begin playing using a video that is has been imported into your project.
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
player.frame = CGRectMake(0, 0, 1024, 768);
[self.view addSubview:player.view];
player.fullscreen = NO;
[player play];
*for example I used a .mp4 filetype
I'm actually using the MPMoviePlayerController for play video in my iPad app.
Actually, I can easly play 1 video but I'm trying to play in the same time 2 video, here is my code :
// Look for the video in the main bundle
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"3idiots.mov" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
NSString *urlStr2 = [[NSBundle mainBundle] pathForResource:#"3idiots.mov" ofType:nil];
NSURL *url2 = [NSURL fileURLWithPath:urlStr2];
videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0, 0,200, 200);
videoPlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:url2];
[self.view addSubview:videoPlayer2.view];
videoPlayer2.view.frame = CGRectMake(0, 300,200, 200);
[videoPlayer2 play];
NSLog(#"Video 1 playing");
[videoPlayer play];
NSLog(#"Video 2 playing");
The first video is correctly launched but not the second. (and btw the second video does not lauch after the first finished)
Here is my output :
2012-06-18 13:47:23.015 testMosaique[2498:11f03] Video 1 playing
2012-06-18 13:47:23.016 testMosaique[2498:11f03] Video 2 playing
Is there a way while using MPMoviePlayerController to play 2 or more videos at the same time?
Thank's
If you want to play more than one video at the same time you have to use AVPlayer frameworks. MPMovie only allowed you play one video at a time.
See AVPlayer documentation.
As Safecase mentioned, MPMovieplayerController will only allow one video to be played at a time. But here is an example to play two simultaneously with the use of AVFoundation:
http://www.sdkboy.com/?p=66
Hope this helps!
What I did is display 4 videos using AVPlayer, but those video are made from 4 another video (I create each videos with AVFoundation). Si I'm able the display thousand and thousand videos in only 4 players, pretty good performances when you play the videos !
I need to play a simple video on my app. I been looking on the internet on how to play a video and I found out that I need to import the MediaPlayer.framwork which I did. I have a Video named:
and the code that I have in order to play it:
NSString *url = [[NSBundle mainBundle]
pathForResource:#"Final_Valores_Pacific"
ofType:#"m4v"];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
I am missing the code to add it to a view but just that code creates a leak:
what is the right way of playing a video? how can avoid that memory leak?
When you alloc an object, you have to release it at the end:
// ...some code
NSString *url = [[NSBundle mainBundle]
pathForResource:#"Final_Valores_Pacific"
ofType:#"m4v"];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
// ...use player
[player release];
Are you getting this leak on the simulator? I got this on an app that I worked on in the past only on the simulator, but not on the iPhone.
There are similar questions about this too:
iPhone: OpenAL & AudioToolbox leak
Hey guys how can I make an app keep playing an mp3 after pressed the hold/power button.
Here is the code I use for preparing the AVAudioPlayer:
- (void)PrepareAudio:(int)index
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#",[_Audio objectAtIndex:Game]] ofType:#"mp3"];
NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
MusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: newURL error: nil];
[newURL release];
[MusicPlayer setVolume: 1.5];
}
And this is the code when I press the button play:
- (IBAction)PushPlay: (id)sender
{
if(!MusicPlayer.playing)
[MusicPlayer play];
}
Best Regards
Carlos Vargas
If you are holding long enough to turn the device off, then there is no way. If you are pressing the button to lock the screen, the music can be played. Why don't you put some code up and let us see what you have tried. Hint: The answer lies within the Audio playback categories.