2015-08-05 27 views
10

Mam AVPlayer z AVPlayerItem. To, czego chcę, to wyłączyć odtwarzanie dźwięku z AVPlayera. Chcę grać po prostu wideo.Wyłączyć odtwarzanie dźwięku w AVPlayer?

Czy ktoś może mi pomóc? Dziękuję Ci!

self.avPlayerItem = [AVPlayerItem playerItemWithURL:self.videoUrl]; 
    self.avPlayer = [AVPlayer playerWithPlayerItem:self.avPlayerItem]; 
    [self.avPlayer play]; 
    self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 


    self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer]; 
    self.avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playerItemDidPlayToEndTime:) 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:self.avPlayerItem]; 


    CGRect screenRect = [[UIScreen mainScreen] bounds]; 

    self.avPlayerLayer.frame = CGRectMake(0, 0, screenRect.size.width , screenRect.size.height); 
    [self.view.layer insertSublayer:self.avPlayerLayer atIndex:0]; 

Odpowiedz

11

AVPlayer została funkcja

@property (nonatomic, getter=isMuted) BOOL muted NS_AVAILABLE(10_7, 7_0); 

Możesz napisać

- (void) muteSound:(BOOL)mute 
{ 
    self.avPlayer.muted = mute; 
} 

i używać go, jak chcesz

- (void) startPlayingVideo 
{ 

    [self muteSound:YES]; 

    //other code 

} 
0

Można wyciszyć dźwięk poprzez wdrożenie następujący kod w viewDidLoad() .

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

// Mute all the audio 
tracksNSMutableArray *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]; 

Poniższe linki mogą ci pomóc.

  1. https://goo.gl/WYJNUF
  2. https://goo.gl/epHNGs
0

W przypadku gdy ktoś szuka Swift 4:

player.isMuted = true // To mute the sound 
player.isMuted = false // To un-mute the sound 

marginesie: wyciszanie film nie resetuje dźwięk wideo, aby rozpocząć. Działa jako zwykła funkcja wyciszenia.

Powiązane problemy