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

x12

macrumors newbie
Original poster
May 20, 2009
27
0
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
 
i used a tutorial that uses AVFoundation/AVAudioPlayer.h
 
i used a tutorial that uses AVFoundation/AVAudioPlayer.h
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.
 
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
 
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?
 
there is a button on this view and the other to switch between the two views
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.