I am trying to play HLS feed in my app using MPMoviePlayerController using Swift.
I am using this below code to play the stream
var url:NSURL = NSURL(string: "streamurl")!
self.moviePlayer = MPMoviePlayerController()
self.moviePlayer.movieSourceType = MPMovieSourceType.Streaming
self.moviePlayer = MPMoviePlayerController(contentURL: url)
self.moviePlayer.prepareToPlay()
self.moviePlayer.shouldAutoplay = true
self.moviePlayer.stop()
self.moviePlayer.view.frame = self.view.bounds
self.view.addSubview(self.moviePlayer.view)
self.moviePlayer.fullscreen = true
self.moviePlayer.setFullscreen(true, animated: true)
self.moviePlayer.controlStyle = MPMovieControlStyle.Embedded
self.moviePlayer.scalingMode = MPMovieScalingMode.AspectFit
self.moviePlayer.play()
My concern is how do I know if live stream is on air or not so that I would inform the user that its not available now.
Hi you can use media server's api to check the stream online status or you can read the content of the m3u8 file is should contain video bit rate and audio bit rate details if the stream is online. i prefer to use the media server api by sending a web request before playing the url.
there is one media server (nimble) offering a service called dispersa
(https://wmspanel.com/dispersa)
which give api access to check the stream status
Related
Is it possible to send cookie with the AVPlayer url?I have a livestream which is AES encrypted and needs a key to decrypt.It will hit the server and the server returns the key only if session is there.So I want to send phpsessionid along with the url to AVPlayer.
Is it possible? I saw AVURLAssetHTTPHeaderFieldsKey.I don't know if it is what I have to set.If so how to do it?
This is how you can set Signed Cookies (Headers) in AVPlayer URL Request :
fileprivate func setPlayRemoteUrl() {
if playUrl.isEmpty { return }
let cookiesArray = HTTPCookieStorage.shared.cookies!
let values = HTTPCookie.requestHeaderFields(with: cookiesArray)
let cookieArrayOptions = ["AVURLAssetHTTPHeaderFieldsKey": values]
let assets = AVURLAsset(url: videoURL! as URL, options: cookieArrayOptions)
let item = AVPlayerItem(asset: assets)
player = AVPlayer(playerItem: item)
playerLayer = AVPlayerLayer(player: player)
playerLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
playerLayer?.contentsScale = UIScreen.main.scale
layer.insertSublayer(playerLayer!, at: 0)
}
In your case FPS(FairPlay Streaming) by apple will work. FairPlay Streaming is DRM(Digital Right Management) support where you will get content key along with your content data and you need to pass through delegate which supports AES-128 encrypt. Please refer below link which i shared below
https://developer.apple.com/streaming/fps/
I haven't really tried it myself but it seems there's an API that let's you create AVURLAsset with options. One of the possible option key is AVURLAssetHTTPCookiesKey. You might want to look into that.
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
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()