Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using local player in iOS to play a video from web

Tags:

ios

iphone

video

I am making a small website for video viewing as a project,

I need to be able to play a video using the local player of the phone, in Android i managed to find the solution:

intent://localhost/video.avi#Intent;action=android.intent.action.VIEW;scheme=http;type=video/mp4;end

This tells the Android OS to open this file using a media player, I need something like this for iOS.

I couldn't find anything on the internet about this, all other posts deal with making an actual application, I don't have access to an iPhone making this even harder to test and play around with it. How can I do this for iPhone? if not possible are there alternatives?

Notice the code is a mere URL and needs absolutely no further implementations

like image 870
bakz Avatar asked Dec 27 '25 20:12

bakz


1 Answers

There's URL Schemes provided by Apple to launch different native stuff via links.

try this: videos://"your video url here"

as an alternative: youtube://"youtube video url here"

About Apple iPhone URL schemes: https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899-CH1-SW1

Building an iOS application you can use AVFoundation framework, it has AVPlayer (samples are in Swift):

let videoUrl = NSURL(string: "video url here")
let videoPlayer = AVPlayer(URL: videoUrl!)
let playerLayer = AVPlayerLayer(player: videoPlayer)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()

you can also use AVPlayerViewController class for it:

let videoUrl = NSURL(string: "video url here")
let videoPlayer = AVPlayer(URL: videoUrl!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
    if let player = playerViewController.player {
        player.play()
    } 
}

or you can use a UIWebView to play video from a player within a web page:

let webview = UIWebView(frame: CGRect(x: 0, y: 0, width: 240, height: 375))
like image 192
Oleh Zayats Avatar answered Dec 30 '25 23:12

Oleh Zayats



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!