shaka-project / shaka-player-embedded

Shaka Player in a C++ Framework
Apache License 2.0
236 stars 63 forks source link

Init player for widevine + player #182

Closed franciscocarodiaz closed 4 years ago

franciscocarodiaz commented 4 years ago

There is a guide to implement in Swift widevine + shaka player using a content with DRM? I'm getting an error and this is my configuration:

class PlayerViewController: BaseViewController, UIGestureRecognizerDelegate { var playerView: ShakaPlayerView? var player: ShakaPlayer?

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(true)

    guard let shakaPlayer = try? ShakaPlayer() else {
        print("Error creating player")
        return
    }

    self.player = shakaPlayer
    self.player?.add(self)
    self.player?.client = self
    let shakaPlayerView = ShakaPlayerView(player: self.player)
    shakaPlayerView.frame = self.view.bounds
    self.playerView = shakaPlayerView
    self.containerPlayerView.addSubview(self.playerView!)

    self.configureAndLoadAssetWithAutoplay()

}

func configureAndLoadAssetWithAutoplay(startTime: Double = 0.0) {
    var urlMedia = getMediaUrl()
    var license = getLicense()

    self.player?.configure("drm.servers.com\\.widevine\\.alpha", with: license)

    self.player?.logLevel = ShakaPlayerLogLevel.V2
    self.player?.load(urlMedia,
                      withStartTime: startTime,
                      andBlock: { error in
                        if let error = error {
                            print("Error loading manifest: \(error.message)")
                        } else {
                            self.player?.currentTime = 0
                            self.player?.play()
                        }
                      })
}

}

extension PlayerViewController: ShakaPlayerClient { func onPlayer(_ player: ShakaPlayer, bufferingChange is_buffering: Bool) { if (is_buffering) { self.loadingIndicator.isHidden = false self.loadingIndicator.startAnimating() } else { self.loadingIndicator.isHidden = true self.loadingIndicator.stopAnimating() } }

func onPlayer(_ player: ShakaPlayer, error: ShakaPlayerError) {
    self.displayAlertAndExit(title: "Shaka Player Error", message: error.message)
}

}

extension PlayerViewController: ShakaPlayerNetworkFilter { func stringArrayToData(stringArray: [String]) -> Data? { return try? JSONSerialization.data(withJSONObject: stringArray, options: []) } func onPlayer(_ player: ShakaPlayer, networkRequest request: ShakaPlayerRequest, of type: ShakaPlayerRequestType, with block: @escaping ShakaPlayerAsyncBlock) { if (type == ShakaPlayerRequestType.license) { request.headers[Globals.PlayerKeys.KEY_ACCESS_TOKEN] = token request.headers[Globals.PlayerKeys.KEY_DEVICE_ID] = xtvupdevice request.headers[Globals.PlayerKeys.KEY_EVENTID] = eventId // This cert.bin is the widevine from widevine if let data: Data = getFile(forResource: "cert", withExtension: "bin") { request.body = data } } block(nil) } func onPlayer( player: ShakaPlayer, networkResponse response: ShakaPlayerResponse, of type: ShakaPlayerRequestType, with block: @escaping ShakaPlayerAsyncBlock) { block(nil) }

}

TheModMaker commented 4 years ago

What error are you seeing? You can still follow the basic tutorial, since Widevine support doesn't require much work. You just need to set license servers. If you need a license filter, you can look at that tutorial.