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()
}
Related
I have an iOS app that streams video on iPhone/iPad devices.
Now I need to get the bitrate on video streaming on the iPhone/iPad device.
ObservedBitrate and IndicatedBitrate does not help with this.
I also came across this below post but few comments mention it works for mpeg4 videos only.
How to check Resolution, bitrate of video in iOS
I'm looking for the bitrate of video streaming on iPhone/iPad and for any video format.
Thanks!
You can listen for AVPlayerItemNewAccessLogEntry notification to get current bitrates for your stream such as:
observedBitrate - aka your current download speed
indicatedBitrate - comes from m3u8 (BANDWIDTH) and means a min bitrate value to play your current stream
Adaptive video playback with AVPlayer can change a current stream to a stream with high or low bandwidth back and forth by network conditions but these changes do not appears on every stalls, network issues etc. because your steam can be buffered, m3u8 doesn't have stream with lower bandwidth to play etc. So if you need to detect a current realtime playback state look to stalls, FPS.
There is sample code in swift but it's easy convertible to objc if you need:
let url = URL(string: "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8")!
let playerItem = AVPlayerItem(url: url)
self.player = AVPlayer(playerItem: playerItem)
NotificationCenter.default.addObserver(forName: .AVPlayerItemNewAccessLogEntry, object: playerItem, queue: nil) { notification in
if let event = playerItem.accessLog()?.events.last {
let bitrates = [event.observedBitrate,
event.indicatedBitrate,
event.averageVideoBitrate,
]
print(">", bitrates)
}
}
player?.play()
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = view.bounds
view.layer.addSublayer(playerLayer)
Outputs:
> [16375938.865617642, 628000.0, 307568.0]
> [nan, 1728000.0, 0.0]
> [9830221.39078689, 2528000.0, 1422032.0]
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 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
I'm trying to play a video of type avi in an application created in xcode written in swift.
The thing is all of the videos I have are in avi and I cannot afford time spent converting the videos right now. Is there a way to play the video in the provided Media player library?
the code I wrote plays the audio of the video only:
func playVideo() {
let path = NSBundle.mainBundle().pathForResource(symbol, ofType:"avi")
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.prepareToPlay()
player.scalingMode = .AspectFill
self.view.addSubview(player.view)
}
or maybe there's a way to convert a video when the function is called?
I,
following the documentation of the MPMediaPlayer :
For movie files, this typically means files with the extensions .mov, .mp4, .mpv, and .3gp
So, unfortunately, you can't use the MPMediaPlayer to read your avi video.
Thanks to VLC for iOs source code, you can re-use it to implement a custom player to read these files.
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()