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];
Related
So in my app i would like to change the in app volume leves for an alarm by the use of the hardware buttons but whenever i use the buttons to turn up or down the volume it ONLY changes the "ringer" volume wich does NOT effect my in app volume.
Under Settings -> Sounds the "change with buttons" switch is ON and everything works fine if i turn it off but most users will want to have it on as well. So when im in my app i want the volume buttons to change the app volume not the ringer volume.
Hope it makes sense
Thanks
By default the hardware buttons will change the alarm volume unless you have an open audio session when they use the buttons. I would recommend opening an AVAudioSession to have them change it or placing a volume slider somewhere in your app to have them change the volume.
This is a difficult problem to solve perfectly because users aren't told what is wrong and many times don't look to see that the ringer volume is what is being changed.
Use MPVolumeView!
If you add an MPVolumeView to your UIWindow (you can make it hidden), the MPVolumeView will automatically take over the hardware buttons for you. The hardware buttons will now affect your app's volume levels instead of the system's.
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
volumeView.showsRouteButton = NO;
volumeView.hidden = YES;
[self.window addSubview:volumeView];
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.
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.
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];
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"]];