Play audio from video when phone is on silent mode - ios

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

Related

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

How do I configure AVPlayer to play a video that was recorded at 120fps?

I have a simple app that records video at 120fps, saves it to the documents directory, and then uses an instance of AVPlayer to play it back.
If I set the playback rate to 1.0 (for the AVPlayer instance), the playback is a bit choppy (probably more along the lines of 60fps). However, if I interrupt the playback by pressing the "play" button (which then sets the playback rate to 1.0 again!), it plays back very smoothly.
For instance, this is what occurs when the user presses the play button (and yes, I observe the 'status' property of AVPlayer before allowing the user to play the video):
- (IBAction)playButtonPressed:(id)sender
{
[self.videoPlayer seekToTime:kCMTimeZero];
[self.videoPlayer setRate:1];
self.videoPlayer.volume = 1;
}
And this is my simple player-setup code:
- (void)setUpAVPlayer
{
self.videoURL = [[NSURL alloc] initFileURLWithPath:self.videoURL.path];
self.videoPlayer = [AVPlayer playerWithURL:self.videoURL];
[self.previewLayer setPlayer:self.videoPlayer];
// observe player status
[self.videoPlayer addObserver:self
forKeyPath:#"status"
options:0
context:nil];
}
There really is nothing unusual about what I'm doing. It plays back video fine. It's only the case where the video was recorded at 120fps that there is a playback issue.
(Also, this is running on my iPhone5s since it is the only device that supports 120fps.)

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.

Movieplayercontroller using a m4v with two audio tracks

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.

Resources