iphone - MPMoviePlayerController - How can I decrease volume of the video programmatically - iphone

I'm using MPMoviePlayerController to play a video which has audio as well. It's working fine.
I'm hiding the default controls. So no controls are showing on the video.
I want to place a slider on the video (I successfully placed a slider as well over the video). With the slider, I want to control the volume of the video that is being played. How can I control volume of video?

See the documentation for MPVolumeView. Here is a sample code that I use in my view controller.
MPVolumeView *systemVolumeSlider =
[[MPVolumeView alloc] initWithFrame: CGRectMake(10, 10, 200, 40)];
[self.view addSubview: systemVolumeSlider];
[systemVolumeSlider release];

Related

MPMoviePlayerController dismisses my UIImagePickerController

I have an iPhone app where I load an UIImagePickerController onto a UIViewController. I then have a custom view on top of the camera. Now when the user takes a photo it is loaded onto a UIImageView which presents it to the user asking if you want to use that photo or take another (removing the image from the UIImageView). This works perfectly.
Now If the user has just recorded a video I wanted to take a snapshot preview somewhere in the video and present it as a static image in the same UIImageView. I do this with the following code:
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] init];
videoPlayer.shouldAutoplay = NO;
[videoPlayer setContentURL:[info valueForKey:UIImagePickerControllerMediaURL]];
UIImage *videoScreenShot = [videoPlayer thumbnailImageAtTime:(videoPlayer.duration/2.0) timeOption:MPMovieTimeOptionNearestKeyFrame];
photoPreview.image = videoScreenShot;
[videoPlayer release]
This works as intended. The problem is if I want to take another video. When I call:
[videoPlayer setContentURL:[info valueForKey:UIImagePickerControllerMediaURL]];
The camera shutter closes and the camera is seemingly dismissed. Trying to take a picture or recording video gives me:
UIImagePickerController: ignoring request to take picture; camera is not yet ready.
UIImagePickerController: ignoring request to start video capture; camera is not yet ready.
I've tried calling the following after, which has no effect:
myImagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
[myImagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
I tried adding the UIImagePickerController to the UIIViewController again, which caused some fantastic freeze-ups.
Finally I tried commenting out the UIViewController's [super didReceivedMemoryWarning] line of didReceivedMemoryWarning. Which also had no effect.
I'm guessing MPMoviePlayerController takes over something UIImagePicker also needs. How do I give it back?
I would suggest setting your MPMoviePlayerController to nil before showing the UIImagePickerController, or maybe taking its view out of the interface temporarily. Both of these contain a movie player view, but there can be only one movie player view at a time in your application's interface. Thus they can interfere with each other, and that might be what's happening to you.

Adding custom controls to a full screen movie

Is it possible to add custom controls to a movie playing in full-screen mode ( with MPMoviePlayerController )? I've seen this in a few streaming apps, and I'm curious how it is done.
You can turn off the standard controls of the player and create custom buttons that call play, pause etc on the player. If you set fullscreen to NO, you can make the players frame whatever you want (fullscreen) and layer your custom controls on top.
Something like:
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] init];
[mp setControlStyle:MPMovieControlStyleNone];
[mp setFullscreen:NO];
[[mp view] setFrame:CGRectMake(myX, myY, myWidth, myHeight)];
[myCustomController setMoviePlayer:mp]; // so controller can send control messages to mp
[myView addSubview:mp.view];
[myView addSubview:myCustomController.view];
or whatever...

Playing videos on iPad with a specific style

i have some mp4 files which are to be played in my iPad app.. I am able to do that quite well. right now i have a play button on blank black space in my app and the video plays after i tap the play button. The user will only come to know the content of the video after playing it.. But, i want the user to know about the video before playing itself . instead of the default black screen i want to show the video starting screen to make the video more interesting. To put it in simple words, i want my video space to be similar to youtube... IS there any way i which this can be done?? Thanks
Subclass MPMoviePlayerController (or however you're playing your video.. if you already use a custom class just add the code in there) and in viewDidAppear initialise a UIImageView with frame size equal to self.view.bounds using whatever background image you want for the loading screen. Add the UIImageView as a subview of self.view and call sendSubviewToBack: on it. When the player is ready to play, it will start drawing video frames on top of your subview, and you should not see it again.
- (void)viewDidAppear
{
UIImageView *loadingImage = [[UIImageView alloc] initWithImage:myImage];
[loadingImage setFrame:self.view.bounds];
[self.view addSubview:loadingImage];
[self.view sendSubviewToBack:loadingImage];
[super viewDidAppear];
}

programmatically off the sound on tapping mute button on iphone

How to programmatically disable the sound when mute button of iphone pressed while playing audio file?
I'm using streamer for audio.
This may help you
Now, here is something from MediaPlayer framework that we are going to use if we want in most easiest way control level of volume in our application. This is very useful if you are implementing an audio player in your app.
The best thing about this small feature is easy implementation in any class. We just import MediaPlayer framework in header of our class (#import ) and add this code below in method we know that is appropriate for this feature (init method).
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 200, 20)] autorelease];
volumeView.center = CGPointMake(150,370);
[volumeView sizeToFit];
[self.view addSubview:volumeView];
This kind of volume control is connected with iPhone hardware volume buttons. You get same thing like in Music player.
You have to use the audio framework of the iOS SDK and choose the correct profile. The system automatically decides if muting is appropriate.
Apple explains it here. :-)
probably you can use ....
if you are using MPMoviewPlayerController and intend to control the volume using mpvolumeview
[[MPMusicPlayerController applicationMusicPlayer] setVolume: 0.0];

AirPlay support, MPMoviePlayerController and MPVolumeView relation

I am developing an iPhone application that has support for video play. I am using MPMoviePlayerController with custom controls for playing the video. For this purpose I have set control style of MPMoviePlayerController to MPMovieControlStyleNone.
I would like to support AirPlay feature for the video being played. As per the documentation, we have to set the 'allowsAirPlay' property of MPMoviePlayerController to YES to enable AirPlay feature. How can I display the AirPlay button on my player UI if I am using MPMoviePlayerController with custom controls?
I have tried the following:
Instantiated MPVolumeView
Set the showsRouteButton and showsVolumeSlider properties of MPVolumeView to NO to hide the volume slider and route button
Added MPVolumeView on my custom player View
I have not given the reference of MPVolumeView and MPMoviePlayerController to each other. But, if 'allowsAirPlay' of MPMoviePlayerController is set to YES then AirPlay button gets displayed on MPVolumeView. How are MPVolumeView and MPMoviePlayerController related? What is the connection between these two classes which are created independently?
Since the MPMoviePlayerController only allows you to play one video at a time, the MediaPlayer framework always knows the video that's playing. That's how MPVolumeView knows about the MPMoviePlayerController. I have no official docs, but I imagine it's baked into the framework this way.
Since there are probably a lot of checks and balances going on (and they loves consistent UIs), Apple only allows you to use their AirPlay button/UI for tapping into this feature. You can, however, put that button wherever you want:
airplayButton = [[MPVolumeView alloc] init];
airplayButton.frame = CGRectMake(myX, myY, 40, 40);
[airplayButton setShowsVolumeSlider:NO];
[customPlayerControls.view addSubview:airplayButton];
I just guessed on the width,height being 40,40 and I'm sure it's not correct, but once I got the button in place it didn't matter.
for (UIButton *button in volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
[button setImage:[UIImage imageNamed:#"custom-route-button.png"] forState:UIControlStateNormal];
[button sizeToFit];
}}
I think this will help you.
The MPVolumeView has an attribute to hide the volume slider and to show the Route button. So there is no need to traverse the views hiding things.
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:myContainerView.bounds] autorelease];
volumeView.showsVolumeSlider = NO;
volumeView.showsRouteButton = YES;
[myContainerView addSubview:volumeView];
The placement of the AirPlay (Route) button may not be what you expect so you may have to play the frame of the container view a bit to get it where you want it.
The answer is: you can't. There is no official method as of iOS 4.3 to provide your own controls for Airplay - you need to use the standard controls if you need that functionality.