I tried to make a simple app that plays live stream from a url.
At the start everything working okay, than after few seconds of playing the video freeze but the audio is still playing on the background.
var mediaPlayer: MPMoviePlayerController = MPMoviePlayerController()
var url = "http://keshethlslive-lh.akamaihd.net/i/c2n_1#195269/master.m3u8"
mediaPlayer.contentURL = NSURL(string: url)
mediaPlayer.view.frame = self.view.bounds
self.view.addSubview(mediaPlayer.view)
mediaPlayer.movieSourceType = MPMovieSourceType.Streaming
mediaPlayer.play()
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!
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.
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.
I am working with an iOS application, in which I have to play the HTTP Live streaming video of file type '.m3u8'. So, I went through some tutorials and some how I've played HTTP live streaming videos in MPMoviePlayerController in iOS.
Now I want to prebuffer the video for 10 seconds in the background to play continue.Please help me with this. I'll be really very grateful to you.
Thanks in Advance.
Here's my code
var moviestreamPlayer : MPMoviePlayerController = MPMoviePlayerController(contentURL: NSURL(string:"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"))
movieStreamPlayer.view.frame = self.view.bounds
self.view.addSubview(movieStreamPlayer.view)
movieStreamPlayer.fullscreen = true
movieStreamPlayer.movieSourceType = MPMovieSourceType.Streaming
// Play the movie!
movieStreamPlayer.prepareToPlay()
movieStreamPlayer.controlStyle = MPMovieControlStyle.Embedded
if(movieStreamPlayer.isPreparedToPlay)
{
movieStreamPlayer.play()
}
I would like to play a video file which is on my local PC (path: "http://192.168.1.5:9000/assets/uploadedFiles/4.mp4"). My iPhone and my PC are both in the same network. My following code works fine if I play videos on my iPhone. Otherwise it displays only a black screen.
self.objMoviePlayerController = MPMoviePlayerController(contentURL: url!)
self.objMoviePlayerController.movieSourceType = MPMovieSourceType.Unknown
self.objMoviePlayerController.view.frame = self.videoView.bounds
self.objMoviePlayerController.scalingMode = MPMovieScalingMode.AspectFill
self.objMoviePlayerController.controlStyle = MPMovieControlStyle.Embedded
self.objMoviePlayerController.contentURL = url!
self.objMoviePlayerController.shouldAutoplay = true
self.videoView.addSubview(self.objMoviePlayerController.view)
self.objMoviePlayerController.prepareToPlay()
self.objMoviePlayerController.play()
I don't want to download the video file to my iPhone. Is there a way to stream the video file from my PC? Thanks