我正在创建一个应用程序,当按下按钮时可以播放声音,并使用可以调节音量的UISlider.有时音量太高,有时甚至在将iphone的音量增加到最大之后也会太低.我如何保持音量始终高?任何可能的方法来集成系统音量和滑块音量?使用MPVolumview会让我的应用程序被拒绝我猜...我在按钮触摸时使用的代码就是这个
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/sound.mp3"];
NSLog(@"Path to play: %@", resourcePath);
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURL fileURLWithPath:resourcePath] error:&err];
player.delegate = self;
[player play];
player.volume=.50;
player.numberOfLoops=-10;
-(IBAction)slidervaluechanged
{ player.volume=slider.value; }
Run Code Online (Sandbox Code Playgroud)
}
是否可以在UIAlertView中放置MPVolumeView?
我试图把它放在里面,但它没有显示.它可能是部分sizeToFit还是initWithFrame:部分?有没有办法测试是否MPVolumeView真的被创建?
这是我初始化UIAlertView和MPVolumeView使用的代码:
UIAlertView *volumeAlert = [[UIAlertView alloc] initWithTitle:@"Volume" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:volumeAlert.bounds];
[volumeAlert addSubview:volumeView];
[volumeAlert sizeToFit];
[volumeAlert show];
[volumeAlert release];
[volumeView release];
Run Code Online (Sandbox Code Playgroud)