0

我正在使用 AVPlayer 在 iPhone 中播放实时流媒体视频。我想关闭播放器的音量(以编程方式)。我试过这个http://developer.apple.com/library/ios/#qa/qa1716/_index.html。但在我的情况下它不起作用。

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[self myAssetURL] options:nil];
NSArray *audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];

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

// Create a player item
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem setAudioMix:audioZeroMix]; // Mute the player item

// Create a new Player, and set the player to use the player item 
// with the muted audio mix
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];

// assign player object to an instance variable
self.mPlayer = player;

// play the muted audio
[mPlayer play];

请为此提出任何解决方案。谢谢

4

1 回答 1

0

您可以使用[此处] 可用的 MPVolumeView类。它有一个音量控制滑块,也适用于 HTTP Live Streams。(http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html

于 2013-06-20T10:07:52.940 回答