volume control?

Discussion in 'iOS Programming' started by x12, Jan 20, 2010.

  1. x12 macrumors newbie

    Joined:
    May 20, 2009
    #1
    hey

    if i am playing a sound in one view, does anyone know if it is possible to control the volume from another, if it is can someone explain how i cant figure it out i have no code to show for the volume

    the sound is called from one view and the volume slider is on another

    plz help
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Which API approach are you using to play the sound?
     
  3. x12 thread starter macrumors newbie

    Joined:
    May 20, 2009
    #3
    i used a tutorial that uses AVFoundation/AVAudioPlayer.h
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Alright. So AVAudioPlayer has a volume property that you can set. So, the trick is making sure your viewController with the slider has access to the instance of the AVAudioPlayer from the first view or, at least, can call a method on the viewController of the first view.

    Also, what's the tutorial? We might be better able to help with this if we can see how the tutorial is handling the AVAudioPlayer.
     
  5. x12 thread starter macrumors newbie

    Joined:
    May 20, 2009
    #5
    the tutorial was on you tube i am not sure which one it was but here is my code for the sound

    Code:
    #import <AVFoundation/AVAudioPlayer.h>
    #import "LeftViewController.h"
    
    
    @implementation LeftViewController
    
    
    
    
    - (IBAction)buttonrm:(id)sender
    {
    	[self dismissModalViewControllerAnimated:YES];
    }
    
    - (IBAction)playl {
    	
    	[theAudio play];
    	
    		
    	
    }
    
    - (IBAction)pausel {
    	
    	[theAudio pause];
    	
    	
    	
    }
    
    /*
     // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
            // Custom initialization
        }
        return self;
    }
    */
    
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
     
     NSString *path =[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"];
     theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
     theAudio.delegate = self;
     //[theAudio play];
    	
    	
     
    	
        [super viewDidLoad];
    }
    
    
    
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
    	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    
    
    
    - (void)didReceiveMemoryWarning {
    	// Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    	
    	// Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
    	// Release any retained subviews of the main view.
    	// e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    
    @end
    
    
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    I'm guessing LeftViewController is for first view you're talking about? If so, does the second viewController have any access to it? I.E. What is the relationship between these views?
     
  7. x12 thread starter macrumors newbie

    Joined:
    May 20, 2009
    #7
    there is a button on this view and the other to switch between the two views
     

Share This Page