tags:

views:

264

answers:

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 can't 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. I have coded both.

The code for the sound is

 #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:@"The Noisettes - Never Forget You" 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

the code for the slider is

 - (void)viewDidLoad {
    [super viewDidLoad];

 CGRect sliderRect = CGRectMake(46,124,169,0);
 UISlider *VolumeL = [[UISlider alloc] initWithFrame:sliderRect];
 VolumeL.minimumValue = 0;
 VolumeL.maximumValue = 100;
 VolumeL.continuous = YES;


 UIImage *sliderctrl = [UIImage imageNamed:@"VolumeL.png"];
 //UIImage *stetchLeftTrack = [[UIImage imageNamed:@"volumel12.png"]
 //stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];


 [VolumeL setThumbImage:sliderctrl forState:UIControlStateNormal];
 //[VolumeL setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];

 [VolumeL addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

 VolumeL.transform = CGAffineTransformRotate(VolumeL.transform, 270.0/180*M_PI);

 [self.view addSubview:VolumeL];

 [VolumeL release];


 }