PDA

View Full Version : Is MPVolumeView supposed to change volume in simulator?




Danneman101
Mar 5, 2009, 03:16 PM
Ive implemented a MPVolumeView with this code:


MPVolumeView *myVolume = [[MPVolumeView alloc] initWithFrame:CGRectMake(10, 435, 300, 0)];
[myVolume sizeToFit];
[moviePlayerWindow addSubview:myVolume];
[myVolume release];


However, when running in the simulator it is set to the far left, which would indicate that the sound is turned off. But it's not. And when moving the bar to the right, it doesnt change the sound-level at all.

So, is this just with the simulator, since the MPVolumeView changes the system volume? Will the MPVolumeView change the volume when run on a real iPhone?



Pring
Mar 5, 2009, 04:36 PM
Correct, it'll work in the device but not the simulator.

Danneman101
Mar 5, 2009, 06:47 PM
Thats a relief :p Thanks for the info :)

TenTouch
Nov 17, 2009, 09:22 AM
You need to add AVFoundation.framework to the project


VolSliderViewController.h

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVAudioPlayer.h>

@interface VolSliderViewController : UIViewController {
UIView *volumeViewSlider;
AVAudioPlayer *audioPlayer;
}




VolSliderViewController.m


- (void)viewDidLoad {
[super viewDidLoad];

//play audio
//the system volume can only be changed if audio is playing otherwise the ringer volume is changed
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/ramzes2.mp3", [[NSBundle mainBundle] resourcePath]]];

NSError *error;

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;

if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];


//implement a system volume slider
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame: CGRectMake(50, 100, 200, 200)] autorelease];
[volumeView sizeToFit];
[self.view addSubview:volumeView];

for (UIView *view in [volumeView subviews]) {
if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
volumeViewSlider = view;
}
}



}

There is no need to use "_updateVolumeFromAVSystemController" it works without it.