如何在xcode for mac中为AVPlayer制作音量滑块

时间:2013-04-16 12:56:42

标签: ios xcode macos volume avplayer

所以我有我的收音机应用程序的简单代码:

 -(IBAction)europaPlus:(id)sender{

        NSLog(@"EuropaPlus work");

        if (clicked ==  0) {

            clicked = 1;

            NSString *urlAddress = @"http://cast.europaplus.ua/europaplus.aac";

            NSURL *urlStream = [NSURL URLWithString:urlAddress];

            radioPlus = [[AVPlayer alloc] initWithURL:urlStream];

            [radioPlus play];}

        else {

            NSLog(@"EuropaPlus not work");

            [radioPlus release];

            clicked = 0;

        }
}

我也只使用AVPLAYER进行URL连接,但是如何在MAC OS中对AVPlayer进行音量控制。我知道IOS中的MPMVolumeControl,但我有mac os项目。谢谢。

1 个答案:

答案 0 :(得分:0)

player = [[AVAudioPlayer alloc] initWithContentsOfURL:
          [NSURL fileURLWithPath:resourcePath] error:&err];
player.delegate = self;
[player play];
player.volume=.number;
player.numberOfLoops=-number;

-(IBAction)slidervaluechanged {

     player.volume=slider.value; 

}

了解更多信息,请查看链接:

http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPVolumeView_Class/Reference/Reference.htmlHow do you implement an MPVolumeView?