Is MPVolumeView supposed to change volume in simulator?

Discussion in 'iPhone/iPad Programming' started by Danneman101, Mar 5, 2009.

  1. macrumors 6502

    Joined:
    Aug 14, 2008
    #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?
     
  2. macrumors 6502

    Joined:
    Sep 17, 2003
    #2
    Correct, it'll work in the device but not the simulator.
     
  3. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #3
    Thats a relief :p Thanks for the info :)
     
  4. macrumors newbie

    Joined:
    Nov 17, 2009
    #4
    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.
     

Share This Page