avplayer has no sounds when play video

后端 未结 5 1872
逝去的感伤
逝去的感伤 2020-12-29 19:44

here is all my codes for play a mp4,the mp4 is playing but no sounds out

import UIKit

import AVFoundation
class ViewController: UIViewController {

@IBOutl         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 20:25

    Its working 100% please try this import AVKit , import AVFoundation and put below code in viewDidLoad() Method.

        do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, options: [])
        }
        catch {
            print("Setting category to AVAudioSessionCategoryPlayback failed.")
        }
    

提交回复
热议问题