avplayer has no sounds when play video

后端 未结 5 1873
逝去的感伤
逝去的感伤 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:19

    For Swift 4.2, put following lines in viewDidLoad

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

提交回复
热议问题