AirPlay support, MPMoviePlayerController and MPVolumeView relation - iphone

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.

Related

MPMoviePlayerViewController, remove quicktime symbol/add background image?

I have an MPMoviePlayerViewController that plays audio. I would like to remove the Quicktime logo and/or add a custom background image to the player but keep the playback controls. I swear I have done this before prior to iOS 5 but I can't re-figure it out! Things I have tried:
-Adding a subview to MPMoviePlayerViewController. Puts the subview OVER the playback controls, not good.
-setBackgroundColor of the moviePlayer with a patternimage. Doesn't do anything.
-setView on the entire MPMoviePlayerViewController. As expected, the playback controls and navigation bar are gone. I suppose this could work but I'd need to recreate all the playback controls manually, but I'd really rather not.
Can anyone shed some light?
Check out the MPMoviePlayerController property backgroundView.
From the MPMoviePlayerController Class Reference;
backgroundView
A customizable view that is displayed behind the movie
content. (read-only)
#property (nonatomic, readonly) UIView *backgroundView
Discussion This
view provides the backing content, on top of which the movie content
is displayed. You can add subviews to the background view if you want
to display custom background content.
This view is part of the view hierarchy returned by the view property.
Availability Available in iOS 3.2 and later. Declared In
MPMoviePlayerController.h
Try something like this (assuming that your instance of the MPMoviePlayerController is called moviePlayerController):
patternView = [[UIView alloc] initWithFrame:self.view.bounds];
patternView.backgroundColor = [UIColor redColor];
[moviePlayerController.backgroundView addSubview:patternView];
[patternView release];
Till's answer is correct for iPhoneOS 3. This has changed in iOS 4 and 5.
Apple has now added a readonly property to MPMoviePlayerViewController exposing a MPMovieController. The MPMovieController has a backgroundView that should be used.
Now you will want to do something like this:
patternView = [[UIView alloc] initWithFrame:self.view.bounds];
patternView.backgroundColor = [UIColor redColor];
[moviePlayerController.moviePlayer.backgroundView addSubview:patternView];
[patternView release];

Change iPhone application volume without volume changed box appearing (app for Japan)

I am making an Augmented Reality application that has picture taking functionality. It uses a custom function of mine to create a UIImage to save the screen. By law in Japan, cameras must have a shutter noise, which is why the iPhone camera always plays it. So far I have found a way to play sounds even when the iPhone is muted but it still relies on the user set volume. So I found a way using MPMusicPlayerController to control the application volume. This works, but when the volume is changed a box pops up signaling that the volume was changed.
Here is my code to play sounds even when muted:
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
I use the library Finch to play the sound (a light wrapper for openAL) and then MPMusicPlayerController to adjust the volume before play.
appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[appMusicPlayer setVolume:0.5f];
Anyone have experience with this or have made apps like this for Japan? I'm really at a loss. Thanks.
The MPVolumeView will, while visible, block the floating box, even if the user can't actually see it.
Some sample code…
// create/synthesize ivars for "MPVolumeView" and "UIView" (both are necessary)
// I called them "mpVolumeView" and "mpVolumeViewParentView" respectively
// the UIView containing the MPVolumeView can have a frame of (0,0,1,1)
// this way, the user never sees the slider, but it still works normally
- (void)viewDidLoad {
...
// with this, only the slider is visible
mpVolumeViewParentView.backgroundColor = [UIColor clearColor];
// initialize the volume slider (link the parent view in IB, or init here)
mpVolumeView = [[MPVolumeView alloc] initWithFrame:
mpVolumeViewParentView.bounds];
// since it's a programmatic init, the subview must be added like so
[mpVolumeViewParentView addSubview:mpVolumeView];
// allows the floating box to appear without destroying mpVolumeView
mpVolumeView.hidden = YES; // or [mpVolume setHidden:YES]; if you prefer
...
}
Before changing volume to force the camera to make sound…
mpVolumeView.hidden = NO; // view visible, box doesn't appear
And after sounds, so it doesn't look like you messed with anything…
mpVolumeView.hidden = YES; // view hidden, box appears
It might take some tweaking to get what you want, but it should be a good starting point.
This code is for iOS 5.1
I don't know what the compatibility is with older versions.

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

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

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

MPMoviePlayer Audio Album art

I am streaming an MP3 file using MPMoviePlayer, and I would like to have an image displayed instead of the default Quicktime logo in the background.
I found out a way to have an image overlay the player, but the problem with that, is you have to tap outside the image to get the player controls to appear. And when they do appear, they are underneath the image.
Does someone know how to do this?
Thanks,
John
backgroundColor is deprecated, and diving into private View structures is dangerous. This worked fine for me:
UIImageView *coverImageView = [[UIImageView alloc] initWithImage:coverImage];
coverImageView.contentMode = UIViewContentModeScaleAspectFit;
coverImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
coverImageView.frame = moviePlayerController.view.bounds;
[moviePlayerController.view addSubview:coverImageView];
Most every app on the iPhone is made of a hierarchy of views. You could go up to the top root node of the movie player and walk down the child views recursively and set the hidden value to YES until you find the right item, then insert your UIImageView below that item. That way, the controls stay on top and still respond to user inputs.
The risk you run is if Apple changes the MPMoviePlayer UI and shuffles the view hierarchy, but you'll probably have lots of advance notice and can patch your app to allow for the new layout.
There is a question as to whether this is kosher for appstore apps, but many current apps (especially camera/picture-taking ones) are doing it to get rid of standard window elements.
Use AVAudioPlayer and implement your own player UI.
it will work check this
MPMoviePlayerController *moviePlayerController=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
moviePlayerController.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Default.png"]];