简体   繁体   English

使用AudioServicesPlaySystemSound播放声音时响起音量控制

[英]Ringing volume control while play sound using AudioServicesPlaySystemSound

I play default /Library/Ringtones provided by Apple 我播放Apple提供的默认/ Library / Ringtones

    AudioServicesPlaySystemSound(soundID);

The sound play perfectly but now I want to increase and decrease volume from my application. 声音播放完美,但现在我想增加和减少应用程序的音量。

I have used below code 我用下面的代码

  musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
  musicPlayer.volume = 0.0625;

But this is deprecated in iOS7.0. 但这已在iOS7.0中弃用。 I want to run app in latest iOS 8.0 我想在最新的iOS 8.0中运行应用

Is there any way that I can do this? 有什么办法可以做到这一点?

Thanks! 谢谢!

I'm using the following code with work perfectly in iOS8: 我在iOS8中完美使用以下代码:

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];        
        NSString *path = [documentsDirectory stringByAppendingPathComponent:@"file.mp3"]
        AVAudioPlayer *player = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil] autorelease];
        player.volume = 1.0f;
        [player prepareToPlay];
        [player setNumberOfLoops:0];
        [player play];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM