Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Danneman101

macrumors 6502
Original poster
Aug 14, 2008
361
1
Ive implemented a MPVolumeView with this code:

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?
 
100% tested

You need to add AVFoundation.framework to the project


VolSliderViewController.h

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

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




VolSliderViewController.m


Code:
- (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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.