AVPlayer is not playing audio in a HLS video stream
Here, i am answering my own question. This issue happened because Shaka Packager (tool to generate HLS segments), did not add the AUTOSELECT=Yes option to the audio track in master .m3u8 file. So, AVPlayer skipped the audio track when playing the video file. This was fixed in the milestone v2.0
Live stream using AVPlayer not playing in iOS 11
Working Code with Live Video Stream
@IBOutlet weak var player_View: UIView!
var LQPlayer: AVPlayer?
let LOW_URL = URL(string:"http://www.streambox.fr/playlists/test_001/stream.m3u8")!
override func viewDidLoad() {
super.viewDidLoad()
self.avPlayerSetup()
LQPlayer = AVPlayer.init(url: LOW_URL)
let avPlayerView = AVPlayerViewController()
avPlayerView.view.frame = self.player_View.bounds
avPlayerView.player = LQPlayer
self.player_View.addSubview(avPlayerView.view)
}
func avPlayerSetup() {
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
try audioSession.overrideOutputAudioPort(AVAudioSessionPortOverride.speaker)
try audioSession.setActive(true)
} catch {
print("AVPlayer setup error \(error.localizedDescription)")
}
}
func initPlayer() {
LQPlayer = AVPlayer(url:LOW_URL)
print("player allocated")
}
func deAllocPlayer() {
LQPlayer = nil
print("player deallocated")
}
@IBAction func playBtn(_ sender: Any) {
// initPlayer()
LQPlayer?.play()
}
@IBAction func pauseBtn(_ sender: Any) {
LQPlayer?.pause()
deAllocPlayer()
}
Related Topics
Start/Stop Image View Rotation Animations
How to Keep the Header Cell Moving with the Tableview Cells in Swift 2.0
How to Rotate a Scnsphere Using a Pan Gesture Recognizer
How Would I Store a Video into Firebase Storage from Swift
How to Draw Text in Center to Uiimage
How to Remove the Black Border of a Textfield
Open a Users Twitter Profile Page from iOS App
How to Manage and Free Memory Through Viewcontrollers
Differrence Between Closure and Function as Argument in Swift
Make Skspritenode Subclass Using Swift
Adding Uigesturerecognizer to Subview Programmatically in Swift
What Are the First Two Columns in Scnmatrix4
How to Create a Ntlm Authentication Header to Use with Alamofire
Xcode 8 How to Show Description of Function While Typing
How to Store JSON Decodable Values into Coredata Using Swift