I want to play video from Server through following code using swift 3 in tableview cell.When i play video from bundle then play successfully.But from server can't play.How i can play?
let url = URL(string: "http://68d07921.ngrok.io/modules/users/client/videos/video.mp4")
avpController = AVPlayerViewController()
avpController.player = AVPlayer.init(url: url!)
avpController.view.frame = self.videoPlayerView.bounds
avpController.showsPlaybackControls = false
self.videoPlayerView.addSubview(avpController.view)
self.videoPlayerView.autoresizesSubviews = true
Related
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 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()
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've just built a custom video player with AVPlayer, and I've found that I can only play video with url containing english character(for example: http://app.ournsarath.com/uploads/videos/mp4s/09_03_2018_business.mp4). Whenever I pass the url containing khmer unicode(for example: http://app.ournsarath.com/uploads/sound/mp3s/01.06.2018Helpingothersចង់ជួយគេ.mp4), the player doesn't play at all.
I'm new to iOS development. Any advice or direction would be appreciated. Thanks!
I've found a solution by encoding the url string before passing it into AVPlayer.
func setupPlayer(link: String){
let encodedString = link.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
if let url = URL(string: encodedString!) {
player = AVPlayer(url: url)
let playerLayer = AVPlayerLayer(player: player)
self.layer.addSublayer(playerLayer)
playerLayer.frame = self.frame
player?.play()
}
I'm looking for some help solving what seems like a simple problem, but I just can't seem to figure it out.
I'm using Haneke from Cocoapods to cache MP4 files from URL (on my server) and then play the cached version using AVPlayer. I'm setting up an AVPreviewLayer inside a UICOllectionViewCell and running this code. The issue is that the player won't play the video initially, but it will play it again in the future (after i scroll back to that cell in the uicollectionview)
let getUrl = NSURL(string: location)
cache.fetch(URL: getUrl!).onSuccess { (data) in
// Hacky way of getting cache URL from Haneke
let basePath = DiskCache.basePath().stringByAppendingPathComponent("shared-data/original/")
let path = DiskCache(path: basePath, capacity: UINT64_MAX).pathForKey(getUrl!.absoluteString)
let fileURL = NSURL(fileURLWithPath: path)
self.player = AVPlayer(URL: fileURL)
let playerLayer = AVPlayerLayer(player: self.player)
playerLayer.frame = self.view.bounds
cell.videoView.layer.addSublayer(playerLayer)
print("Playing video")
self.player.play()
}