Skip to content

A simple YouTube player made with WKWebView. With the observer to listening the player status. Can be used in UIView, UIViewController and SwiftUI.

License

Notifications You must be signed in to change notification settings

bcbod2002/webview-youtube-player

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebView-Youtube-Player

Overview

It's a simple Youtube player that you can use it straight away. But haven't tested in the table view / collection view / lazy grid.

Swift Package Manager

Add the following line in your Package.swift

.package("https://github.com/bcbod2002/webview-youtube-player", branch: "master")

Add webview-youtube-player to target's dependencies.

.target(
    name: "TargetName",
    dependencies: ["YoutubeWebView"]
)

Usage

UIKit

import YoutubeWebView

final class ViewController: UIViewController {

    @IBOutlet weak var playerView: YoutubeWebUIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let witness = YoutubeWitness()
            .onReady { incident in
                // Observe player on ready incident
            }
            .onStateChange { incident in
                // Observe player state change incident
            }
            .onQualityChange { incident in
                // Observe player quality change 1st incident
            }
            .onQualityChange { incident in
                // Observe player quality change 2nd incident
            }

        playerView.add(witness)

        // If you want to play the video automatically
        try? playerView.arrange(videoIDs: ["drCnFueS4og"], autoPlay: true)

        // If you want to play the video by yout control
        try? playerView.arrange(videoIDs: ["drCnFueS4og"])
        playerView.execute(.play)
    }
}

SwiftUI

import YoutubeWebView

struct ContentView: View {
    var body: some View {
        YoutubeWebView(videoIDs: ["drCnFueS4og"], autoPlay: true)
                .onReady { incident in
                    // Observe player on ready incident
                }
                .onStateChange { incident in
                    // Observe player state change incident
                }
                .onQualityChange { incident in
                    // Observe player quality change 1st incident
                }
                .onQualityChange { incident in
                    // Observe player quality change 2nd incident
                }
    }
}

License

License: MIT This code is distributed unter the terms and conditions of the MIT license

About

A simple YouTube player made with WKWebView. With the observer to listening the player status. Can be used in UIView, UIViewController and SwiftUI.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published