iOS AVPlayer播放视频没声音

如果使用AVPlayer来播放视频,出现有画面却没声音的情况。只需要添加一下几行代码即可:

    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayAndRecord
           withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
                   error:nil];

AVAudioSession是音频会话的一个单例,将指定该APP在与系统之间的通信中如何使用音频。

你可能感兴趣的:(iOS AVPlayer播放视频没声音)