recently I have see that one of my apps feature stopped working. The main problem is that, now, I can play instagram videos from an URL. This feature was working time ago, but I can not say how time is broken because I have noticed the problem now.
For example, I have this URL from Instagram:
https://embed.storiesig.net/aHR0cHM6Ly9zY29udGVudC1hdGwzLTIuY2RuaW5zdGFncmFtLmNvbS9vMS92L3QxNi9mMS9tMTcvQzQ0NjhFNDI4NTkwN0JCM0M3QkREQjFEQ0MzMTJCODhfdHJhbnNjb2RlX291dHB1dF9kYXNoaW5pdC5tcDQ/ZWZnPWV5SnhaVjluY205MWNITWlPaUpiWENKcFoxOTNaV0pmWkdWc2FYWmxjbmxmZG5SelgyOTBabHdpWFNJc0luWmxibU52WkdWZmRHRm5Jam9pZG5SelgzWnZaRjkxY214blpXNHVOekl3TG5OMGIzSjVMbVJsWm1GMWJIUWlmUSZfbmNfaHQ9c2NvbnRlbnQtYXRsMy0yLmNkbmluc3RhZ3JhbS5jb20mX25jX2NhdD0xMDUmdnM9MTc4NzE0ODIzOTk2MjExNTBfMzM4ODI0NTY4MiZfbmNfdnM9SEJrY0ZRSVlXR2xuWDNOMGIzSnBaWE5mY0dWeWJXRnVaVzUwWDNCeWIyUXZRelEwTmpoRk5ESTROVGt3TjBKQ00wTTNRa1JFUWpGRVEwTXpNVEpDT0RoZmRISmhibk5qYjJSbFgyOTFkSEIxZEY5a1lYTm9hVzVwZEM1dGNEUVZBQUxJQVFBb0FCZ0FHd0dJQjNWelpWOXZhV3dCTVJVQUFDYjBvdWpjbG8zRVB4VUNLQUpETXl3WFFCUUFBQUFBQUFBWUVtUmhjMmhmWW1GelpXeHBibVZmTVY5Mk1SRUFkZWdIQUElM0QlM0QmY2NiPTktNCZvZT02MUIzRURDRSZvaD05ZjIyMmE3NWYxZmE1ZmYzNDlhZGM4MWNhNzFhZjExNCZfbmNfc2lkPWJhYjYzOA==
If you open the URL in web browser (Safari, Chrome, etc...) you will see the video running.
But If I try to play the video from a AVPlayer like it used to work, the video is not played. My code for video playback is like this:
let videoUrl = story.videoUrl!
if (videoUrl.absoluteString.lengthOfBytes(using: .utf8) > 0) {
let player = AVPlayer(url: videoUrl)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
}
Where story.videoUrl is the URL of the example. If yo play the URL in a AVPlayer you will see nothing, so I don't know what is going on.
Related
I am developing an iOS app in Swift that plays audio files on TV over Google Cast.
App uses two-way communication over TextChannel to exchange information with the receiver app.
The app is working as expected until I put the app into the background. After the app is backgrounded the Google Cast session gets disconnected.
To ensure app is not susspended in the background while playing audio I have in my AppDelegate this code snippet:
try session.setCategory(AVAudioSession.Category.playback,
mode: AVAudioSession.Mode.default,
options: [AVAudioSession.CategoryOptions.mixWithOthers, AVAudioSession.CategoryOptions.allowAirPlay])
try session.setActive(true)
This is how I initialise the Google Cast:
let criteria = GCKDiscoveryCriteria(applicationID: kReceiverAppID)
let options = GCKCastOptions(discoveryCriteria: criteria)
options.suspendSessionsWhenBackgrounded = false
GCKCastContext.setSharedInstanceWith(options)
GCKCastContext.setSharedInstanceWith(options)
If I add a dummy AVPlayer to my ViewController and play a random mp3 file on the player while I play other audio files overcast connection to the Google Cast session remains connected and the app works as expected until mp3 stops playing on AVPlayer.
Here is my AVPlayer snippet:
let videoURL = URL(string: "https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_5MG.mp3")
let player = AVPlayer(url: videoURL!)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()
Can anybody help me prevent the app from being suspended when it plays audio only while casting to TV?
Thanks!
My following code plays the "fox village.mp4" video, which is commented out, but not the you tube link and gives this error:
AddInstanceForFactory: No factory registered for id F8BB1C28-BAE8-11D6-9C31-00039315CD46
Please help if you can. Thanks!!
let videoURL = URL(string: "https://youtu.be/MTNCcC_H3oM")!
// let videoURL = URL(string: "https://wolverine.raywenderlich.com/content/ios/tutorials/video_streaming/foxVillage.mp4")!
let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
player.play()
The first thing you need to clear that AVPlayer does not have the capacity to play youtube video from URL.
Note:
One thing you need to keep in your mind, AVPlayer is able played video if URL is direct downloadable.
In your case, you need to go with below solutions
Solution: 1
To play a youtube video, You need to go with the WKWebView or WKWebView with iFrame
OR
I suggest you need to go with YTPlayerView
OR
How to embed a Youtube video into my app?
At first I want to mention that I'm using MobilePlayer library but it's just a skin above AVPlayer.
When I tap to play video it only plays sound and I do not see any video. I've checked view bounds but the problem is not there. At the beginning of the video it indicates loading progress but later I hear only the sound without any video.
My code looks like:
let bundle = Bundle.main
let config = MobilePlayerConfig(fileURL: bundle.url(
forResource: "Skin",
withExtension: "json")!)
let videoURL = NSURL(string: channelURL!)
self.playerVC = MobilePlayerViewController(contentURL: videoURL! as URL, config: config)
self.playerVC.activityItems = [videoURL! as URL]
self.present(self.playerVC, animated: true)
I also want to mention that I see the video when I run on the simulator but on the real device there is no video at all. What can be a problem?
If you need any part of the code just ask me please
I work on an iOS app that bring videos and images from server, each object have many images and videos, I need to show these images and videos in a slider (pager) where user can slide to get the next one, and I need these videos and images cached in device, I google that and I found this pod but it not play video which is a few seconds infinitely, and I try to play the provided video URL in example of pod and it's also have the same issue, are there any alternative solution or any solution for this pod?
First of all create a UIView outlet for display image or Video then you can use this code `
let avPlayer = AVPlayer()
let videolink = (videosString[indexPath.row] as? String)!
let videoURL = NSURL(string: videolink)
avPlayer = AVPlayer(url: videoURL! as URL)
let playerLayer = AVPlayerLayer(player: avPlayer)
playerLayer.frame = CGRect(x: cell.videoview.frame.origin.x, y: cell.videoview.frame.origin.x, width: cell.videoview.frame.size.width, height: cell.videoview.frame.size.height)
cell.videoview.layer.addSublayer(playerLayer)
avPlayer.play()`
like videoVideo is a view where you wish to play a video(avplayer will add a layer to that view)
To present Image, you can use SKPhotoBrowser
to differentiate Image and Video you can use bool
Hope you got it
If you need any help ask me i can code for you
HI I'm developing Broadcast App for that I'm using Videocore library now how can i play that streaming video in ios app i tried with the MpMoviePlayer but it won't support the rtmp stream. so is there any third party libraries available for RTMP supported Players please help me
If you already have the RTMP live stream ready and playing as HLS then you can simply add .m3u8 after the stream name and make RTMP link to http. For example you have RTMP link like this:
rtmp://XY.Y.ZX.Z/hls/chid
You have to just make the url like this:
http://XY.Y.ZX.Z/hls/chid.m3u8
and it will play smoothly in iOS. I have tried following code and it is working fine.
func setPlayer()
{
// RTMP URL rtmp://XY.Y.ZX.Z/hls/chid be transcripted like this http://XY.Y.ZX.Z/hls/chid.m3u8 it will play normally.
let videoURL = URL(string: "http://XY.Y.ZX.Z/hls/chid.m3u8")
let playerItem = AVPlayerItem(url: videoURL!)
let adID = AVMetadataItem.identifier(forKey: "X-TITLE", keySpace: .hlsDateRange)
let metadataCollector = AVPlayerItemMetadataCollector(identifiers: [adID!.rawValue], classifyingLabels: nil)
//metadataCollector.setDelegate(self, queue: DispatchQueue.main)
playerItem.add(metadataCollector)
let player = AVPlayer(playerItem: playerItem)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
self.player = player
player.play()
}
But it will be slow and laggy because of the high resolution video stream upload. If you make the resolution to low when uploading the video stream, it will work smooth in low bandwidth network as well.