Movieplayercontroller using a m4v with two audio tracks - ios

I need use in my App a m4v video with two audio tacks. But when I play the video, it starts with the two audio tracks at the same time. I need to load the audio track with the device's default language (English by default).
Here is my code:
_moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[_moviePlayer shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
_moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self presentMoviePlayerViewControllerAnimated:_moviePlayer];

MPMoviePlayerController just as well as the wrapping MPMoviePlayerViewController do not support the selection of audio tracks.

Related

Play audio from video when phone is on silent mode

I am building an application that plays certain video files. However, when the phone is on vibrate the audio still plays. Apps like youtube still play the audio form their videos when the phone is on vibrate. How can I do this? I am using avplayer to play the video. Below is my code for playing the video
_player = [[AVPlayer alloc]initWithPlayerItem:pi];
AVPlayerViewController *playerController = [[AVPlayerViewController alloc]init];
playerController.player = _player;
[self presentViewController:playerController animated:YES completion:nil];
playerController.view.frame = self.view.frame;
[_player setMuted:false];
[self addChildViewController:playerController];
Found the solution. Adding this code allows whatever video is playing to produce audio even on silent mode.
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: nil];

iPhone SDK play mp4, avi, flv, 3gp, wmv formats on iphone app

I have been in developing an iPhone app. In this app, I need to play various video files. I am using UIWebView with AVPlayer to play video file. mp4 videos are playing properly. But other formats (avi, flv, 3gp, wmv) are not playing.
My code works for mp4 but not for avi, flv, 3gp, wmv.
weakSelf.player = [AVPlayer playerWithURL:fileUrl];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = weakSelf.player;
[weakSelf addChildViewController:controller];
[weakSelf.view addSubview:controller.view];
controller.view.frame = CGRectMake(weakSelf.webViewParentView.frame.origin.x, weakSelf.webViewParentView.frame.origin.y, weakSelf.browserWebView.frame.size.width, weakSelf.browserWebView.frame.size.height);
//NSLog(#"eeerror %# ",[weakSelf.player error]);
//controller.view.frame = weakSelf.browserWebView.frame;
[weakSelf.player play];
How do I configure the app to play formats other then mp4?
Any suggestions are appreciated.

How to play audio in iOS with UI of music player?

I am trying to play audio in iOS using AVPlayer but i am not able to see any Deafault UI fro playing the audio. Here is my code
NSURL *url = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
playerItem = [AVPlayerItem playerItemWithURL:url];
player = [AVPlayer playerWithPlayerItem:playerItem];
player = [AVPlayer playerWithURL:url];
[player play];
Audio os played but not any audio player UI is diplayed as in case of MPMoviePlayerController UI is shown while playing the video.Please tell me the solution here?
iOS is not providing any native kind of the UI for Playing Audio for that.you create own UI and that manage by the developer thru AVAudioPlayer class.
Here is tutorial for the custom Playing Audio with AVAudioPlayer

MPMoviePlayerController fail to play audio

I use MPMoviePlayerController to play a list of audio streams from url. I use the following code to init the player
self.player = [[[MPMoviePlayerController alloc] init] autorelease];
self.player.controlStyle = MPMovieControlStyleNone;
and later use the following code to set and reset contentUrl:
self.player.contentURL = url;
[self.player prepareToPlay];
but sometimes, not every time, it fails to play audio, post MPMoviePlayerPlaybackDidFinishNotification directly and gives following userInfo
{
MPMoviePlayerPlaybackDidFinishReasonUserInfoKey = 1;
error = "Error Domain=MediaPlayerErrorDomain Code=-11828 \"Cannot Open\" UserInfo=0xee7bf20 {NSLocalizedDescription=Cannot Open}";
}
anyone knows why?
I would suggest you use AVPlayer instead of MPMoviePlayerController.
I had seen such issues before when streaming audio with MPMoviePlayerController. AVPlayer is the more appropriate one for this task.

Open movie app with precise video on iOS

I would like to open the iPad movie player from my app to play a video.
The video will already be on the device, and the app is destined to ad-hoc distribution on pre-configured device, thus we can say the video will always be here.
My problem is that I can't figure out how to open the video app! I've searched a lot of things, including UTI, or embedded video, but that doesn't meet my needs.
Is there any way to simply open the player with the specified file ?
Do you need to open the video app per se? Or do you just need to play local video file from your app? In the latter case, you can just use MPMoviePlayerController (or the wrapping MPMoviePlayerViewController for iOS > 3.2).
Something like this works for me.
NSURL * url = [[NSBundle mainBundle] URLForResource:#"yourvideo" withExtension:#"mov"];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.view.frame = self.view.bounds;
player.movieSourceType = MPMovieSourceTypeFile;
[self.view addSubview:player.view];
player.shouldAutoplay = NO;
player.fullscreen = YES;
[player prepareToPlay];

Resources