Jacob Williamson
Jacob Williamson

Reputation: 21

Streaming Video via Swift 3

Right now my task is to stream a video from a site like this http://watchers.to/sazktfmnvzqc.html on an iPhone. (Be warned, there are tons of pop ups)

I've tried using a UIWebView to simply open up a portal for clicking the video at that URL, but honestly they're so many pop ups its actually impossible.

Is there any clever way to circumvent this that you all can think of? Like code that I could use to instantly click underneath the popup overlay or even click on the overlay the required amount of times, instantly reloading back from the new page to stream the video? Just looking for a direction to go.

Thanks!

Upvotes: 2

Views: 4290

Answers (2)

dscrown
dscrown

Reputation: 578

I got if from here. Worked for me.

https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/MediaPlaybackGuide/Contents/Resources/en.lproj/GettingStarted/GettingStarted.html

func play (){
    //Your video path URL
    guard let url = URL(string: "http://www.xxx.xxx/xx/xxxx/xxxxxxx.mov") else {return}

    let player = AVPlayer(url: url)
    let playerController = AVPlayerViewController()
        playerController.player = player
    self.present(playerController, animated: true) {
        player.play()
    }
}

Upvotes: 1

kchromik
kchromik

Reputation: 1388

First you have to know the exact URL of the video. Then you can use an AVPlayerViewController, which needs an AVPlayer initialised with this URL.

Example:

import AVFoundation // this you need for the `AVPlayer`
import AVKit // this is for the `AVPlayerViewController`

let viewController = AVPlayerViewController()
let videoURL = "http://you.videourl.com"

if let player = AVPlayer.playerWithURL(videoURL) as? AVPlayer {
    viewController = player
}

Then you can push the view controller and play the video.

Upvotes: 1

Related Questions