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()
Related
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)
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()
}
I'm using AVPlayerViewController for playing video it works fine with iOS 11 but the same code doesn't work in iOS 12. could anyone help me to fix this issue please?
let url: URL = Bundle.main.url(forResource: "sampleVideo", withExtension: ".mp4")!
let avAsset = AVURLAsset(url: url)
let playerItem = AVPlayerItem(asset: avAsset)
player = AVPlayer(playerItem: playerItem)
playerController = AVPlayerViewController()
playerController?.player = player
playerController?.view.frame = videoHolderView?.bounds ?? CGRect.zero
guard let videoView = playerController?.view else { return }
videoView.tag = 101
videoHolderView.addSubview(videoView)
player?.play()
Finally figured out the issue!!!
in iOS 12 if you disable PlayBackControls of AVPlayerController, AVPlayer will still consume the tap gesture.
playerController?.showsPlaybackControls = false
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.
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)