2016-10-22 88 views
-1
- (void)playVideoInteractionNarration:(NSString *)vNarr{ 

[self pauseActionExecution]; 

NSURL *u = [NSURL fileURLWithPath:vNarr]; 
AVQueuePlayer *player = [[AVQueuePlayer alloc] initWithURL:u]; 
self.controller = [[AVPlayerViewController alloc]init]; 
controller.player = player; 
controller.showsPlaybackControls=NO; 

[controller.player setActionAtItemEnd:AVPlayerActionAtItemEndAdvance]; 

[[NSNotificationCenter defaultCenter] 
addObserver:self 
selector:@selector(videoNarrationFinishedPlaying:)             
name:AVPlayerItemDidPlayToEndTimeNotification 
object:player.currentItem]; 
//NSLog(@"MPVIDEOOOOOOO %@", player); 

[controller.player setVolume:1.0]; 
[controller.player setMuted:NO]; 
[controller setViewInCurrentController]; 
[controller.player play]; 

} 

- (void)videoNarrationFinishedPlaying:(NSNotification *) aNotification{ 

AVPlayerItem * item = [aNotification object]; 

[self.controller removeViewInCurrentController]; 
[[NSNotificationCenter defaultCenter] removeObserver:self 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:item]; 

[self.controller.player pause]; 
[self.controller release]; 
[self playActionExecution]; 
} 

視頻開始和完成正確但沒有聲音 爲什麼?AVQueuePlayer播放但沒有聲音

+0

你測試是在設備或模擬器應用程序? –

+0

沒有在設備上... –

+0

有沒有設備振動模式?或在聲音中,然後增加您的默認聲音 –

回答

0

正確的答案是這樣的:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 
0
@import AVKit; 
@import AVFoundation; 
@property (nonatomic) AVPlayer *avPlayer; 



NSURL *fileURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]; 
    self.avPlayer = [AVPlayer playerWithURL:fileURL]; 
    self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

    AVPlayerLayer *videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer]; 
    videoLayer.frame = self.view.bounds; 
    videoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    [self.view.layer addSublayer:videoLayer]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:[self.avPlayer currentItem]]; 

    [self.avPlayer play]; 

試試這個代碼和評論你的一個,並檢查您的設備做了有益的工作或沒有?

+0

聲音工作與否? –

+0

我不得不改變一下代碼,因爲我沒有[self.view.layer addSublayer:videoLayer]; –

+0

但聲音...不,我不聽聲音抱歉... –