Swift: Streaming video file from pc - ios

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

Related

Using ReplayKit & HTTPStream and cast to Chromecast

I need to use Replaykit (Broadcast extension UI) to be able to cast content from iPhone to TV (Chrome cast).
Currently I am using Haishinkit library, I have written content to HTTPStream (CMSampleBuffer), I use this URL and cast to TV, it doesn't work.
let url = URL.init(string: "abc.m38u")!
let mediaInfoBuilder = GCKMediaInformationBuilder.init(contentURL: url)
mediaInfoBuilder.streamType = GCKMediaStreamType.buffered
mediaInfoBuilder.contentID = mediaURL.absoluteString
mediaInfoBuilder.contentType = mediaURL.mimeType()
mediaInfoBuilder.hlsSegmentFormat = .TS
mediaInfoBuilder.hlsVideoSegmentFormat = .MPEG2_TS
mediaInfoBuilder.streamDuration = .infinity
Where am I going wrong.
Can I use any other way to stream content to Chromecast, because using HTTPStream, the content is deleyed for about 5 to 10 seconds.
Thanks.

AVPlayer does not display any video on physical device but displays on the simulator

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

How to play RTMP video streaming in ios app?

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.

To check if a HLS feed is onair or not

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

stream video freeze after few seconds

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()

Resources