Video stream is not playing in AVPlayer - ios

Video stream is not working with partial content byte streaming web API.
let headerFields:[String: String] = ["Range":"bytes"]
let avAsset = AVURLAsset(url:url, options: ["AVURLAssetHTTPHeaderFieldsKey": headerFields])
let playerItem = AVPlayerItem(asset: avAsset)
self.player = AVPlayer(playerItem: playerItem)

Related

Playing mpga format files with AVPlayer in ios swift

I tried to run a remote mpga format audio file with AVPlayer in ios and doesn't play. Below code works fine for remote mp3 files. Can i change the MIME type for the file loaded or are there any options to play the mpga file in ios.
let audioUrl = "https://example-files.online-convert.com/audio/mpga/example.mpga"
let url = URL(string: audioUrl)
let player: AVPlayer = AVPlayer(url: url!)
player.play()
console shows
nw_endpoint_flow_copy_multipath_subflow_counts Called on non-Multipath connection
let audioUrl = "https://example-files.online-convert.com/audio/mpga/example.mpga"
if let url = URL(string: audioUrl){
let playerItem = AVPlayerItem(url: url)
let player: AVPlayer(playerItem: playerItem)
player.play()
}

Unable to play streaming audio

I want to play streaming audio on an iOS app. I use this code to play audio:
let url = URL(string: "http://online.radiorecord.ru:8102/chil_320.m3u")!
let asset = AVAsset(url: url)
let playerItem = AVPlayerItem(asset: asset)
let player = AVPlayer.init(playerItem: playerItem)
player.play()
When I run the app on the Simulator I get this error:
2018-11-30 21:57:26.097577+0300 radio[7417:21800733]
[AudioHAL_Client]
AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:
AudioObjectRemovePropertyListener: no object with given ID 0
How to fix this issue?
var player: AVPlayer?
let url = URL(string: "http://online.radiorecord.ru:8102/chil_320.m3u")!
player = AVPlayer(url: url)
player?.play()

AVPlayerViewController Showing Black Screen

I am trying to play a video in AVplayer with below code but it's showing black screen.I also tried googling but didn't get any luck
let url = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let asset = AVURLAsset(url: url!)
let item = AVPlayerItem(asset: asset)
let player = AVPlayer.init(playerItem: item)
let playerController = AVPlayerViewController()
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
I also added plist entry for TransportSecurity.

Update my AVURLAsset while the video is playing (swift)

i'm playing an encrypted m3u8 file and i need to send a new "mykey" update value after certain time to the player.
let headers = ["Authorization": "mykey"]
let avAsset = AVURLAsset(url: videoURL, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])
let avItem = AVPlayerItem(asset: avAsset)
let avPlayer = AVPlayer(playerItem: avItem)
how could i access to the AVURLAsset from the player later on to update my value?
I don't have find anything under...
self.avPlayer.items()[0].asset...
Just call the replaceCurrentItem(with:) function of AVPlayer, Documentation here
let newAvItem = AVPlayerItem(asset: newAvAsset)
avPlayer.replaceCurrentItem(with: newAvItem)

How do I play 30 seconds of an avplayeritem?

I can play the whole entire song, but I want to only play 30 seconds of it. How would I do that?
if let url: String = "hiddingthelink"{
let urlplayer = NSURL(string: url)
let playeritem = AVPlayerItem(URL:(urlplayer)!)
player = AVPlayer(playerItem: playeritem)
self.player.volume = 1.0
self.player.rate = 1.0
self.player.play()
}

Resources