Play multiple videos - iphone

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 !

Related

alert sound when start recording

First time i am capturing video in my App, but when i start capturing i want that button click sound as native application. I have searched a lot and came to know that it is a system sound. Can anyone please tell me how can i add that sound in my application when i start capturing video and when i stop capturing.
Currently i am using AVAudioPlayer to play sound as shown below
NSURL *url1 = [[NSBundle mainBundle] URLForResource:str withExtension:#"wav"];
_startAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:nil];
_startAudioPlayer.delegate= self;
[_startAudioPlayer prepareToPlay];
[_startAudioPlayer play];
Thanks in advance.....
Just import AudioToolbox.framework.
Create the URL for the source audio file
NSURL *tapSound = [[NSBundle mainBundle] URLForResource: #"tap"
withExtension: #"aif"];
// Store the URL as a CFURLRef instance
self.soundFileURLRef = (CFURLRef) [tapSound retain];
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (
soundFileURLRef,
&soundFileObject
);
Play sound
AudioServicesPlayAlertSound (soundFileObject);
Here is a nice tutorial link you can follow this
When you want to start capturing video at that time call this bellow method like this...
[self playSound];
use my this bellow method for play sound...
-(void)playSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"adriantnt_release_click" ofType:#"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
first store any mp3 or any audio file in your project folder For Ex: i add adriantnt_release_click.mp3 file.
Also add AVAudioPlayerDelegate in your .h file and add AudioToolbox.framework in your project..

Issue with playing video file

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

How can i add videos to iphone app [duplicate]

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

Playing a Movie from MPMediaItem (iPad/IOS5)

I need to play a movie already synchronised from iTunes to Apples 'Movies' App on a iPad, in a view.
I can play a movie from the bundle using MPMoviePlayerController OK. I can get a media Item of all movies (NSArray of MPMediaItem's using MPMediaQuery). However the MPMoviePlayerController only accepts an NSURL - not an MPMediaItem.
So, how can I play a movie when all I have is a MPMediaItem of the movie? Is there another object other than MPMoviePlayerController that does this? Several posts explain how to 'get' a media item but not how to 'set' an item.
Any help is greatly appreciated.
each MPMediaItem has an URL which can be accessed with valueForProperty:.
I don't know if you can use that to play it in MPMoviePlayerController though. In theory it should work.
NSURL *url = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
EDIT: Looks like it's not possible to use that.
MPMediaItemPropertyAssetURL
A URL pointing to the media item, from which an AVAsset object (or other URL-based AV Foundation object) can be created, with any options as desired. Value is an NSURL object.
The URL has the custom scheme of ipod-library. For example, a URL might look like this:
ipod-library://item/item.m4a?id=12345
Usage of the URL outside of the AV Foundation framework is not supported.
from: General Media Item Property Keys
Try this
NSURL *url = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: url];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
[player play];
i think this should work..
MPMediaItem is inherited from MPMediaEntity which has the method valueForProperty:

Memory leaks when playing a video iPhone

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