2016-08-02 49 views
0

我使用AVPlayer爲我的應用程序使用HTTP實時streaming.Now我想實現該音頻流的電平表。 我發現了幾個使用AVAudioPlayer的例子。但我找不到解決方案來獲取所需的信息。如何在iOS中設置AVPlayer聲級計?

AVPlayer.NSURL *url = [NSURL URLWithString:@"http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3"]; 
self.playerItem = [AVPlayerItem playerItemWithURL:url]; 
self.player = [AVPlayer playerWithPlayerItem:self.playerItem]; 
self.player = [AVPlayer playerWithURL:url]; 
[self.player play]; 
+0

[AVPlayer音量控制]的可能的複製(http://stackoverflow.com/questions/15569983/avplayer-volume-control) – KIDdAe

+0

檢查:HTTPS: //github.com/akhilcb/ACBAVPlayerExtension – adev

回答

1

請試試這個

if ([mPlayer respondsToSelector:@selector(setVolume:)]) { 
    mPlayer.volume = 0.0; 
} else { 
    NSArray *audioTracks = mPlayerItem.asset.tracks; 

    // Mute all the audio tracks 
    NSMutableArray *allAudioParams = [NSMutableArray array]; 
    for (AVAssetTrack *track in audioTracks) { 
     AVMutableAudioMixInputParameters *audioInputParams =[AVMutableAudioMixInputParameters audioMixInputParameters]; 
     [audioInputParams setVolume:0.0 atTime:kCMTimeZero]; 
     [audioInputParams setTrackID:[track trackID]]; 
     [allAudioParams addObject:audioInputParams]; 
    } 
    AVMutableAudioMix *audioZeroMix = [AVMutableAudioMix audioMix]; 
    [audioZeroMix setInputParameters:allAudioParams]; 

    [mPlayerItem setAudioMix:audioZeroMix]; // Mute the player item 
} 
+0

NSURL * url = [NSURL URLWithString:@「http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3」]; self.playerItem = [AVPlayerItem playerItemWithURL:url]; self.player = [AVPlayer playerWithPlayerItem:self.playerItem]; self.player = [AVPlayer playerWithURL:url]; [self.player play]; 此代碼將播放流很好,我不知道如何實現你的給定的代碼與此。 – Selvarani