Selvarani
Selvarani

Reputation: 31

How to set AVPlayer Sound Level meter in iOS?

I'm using AVPlayer for my app using HTTP live streaming.Now I want to implement a level meter for that audio stream. I found several examples using AVAudioPlayer. But I cannot find a solution for getting the required informations off.

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];

Upvotes: 0

Views: 643

Answers (1)

Monika Patel
Monika Patel

Reputation: 2375

Please try this one

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
 }

Upvotes: 1

Related Questions