All Projects → dailymotion → Dailymotion Swift Player Sdk Ios

dailymotion / Dailymotion Swift Player Sdk Ios

Licence: mit
Dailymotion Player SDK for iOS in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Dailymotion Swift Player Sdk Ios

Vue Video Player
🎞 @videojs component for @vuejs
Stars: ✭ 4,026 (+13782.76%)
Mutual labels:  player, video-player
Xgplayer
A HTML5 video player with a parser that saves traffic
Stars: ✭ 4,792 (+16424.14%)
Mutual labels:  player, video-player
Videojs Resolution Switcher
Resolution switcher adds the ability to select the video quality in video.js player.
Stars: ✭ 375 (+1193.1%)
Mutual labels:  player, video-player
Dkvideoplayer
Android Video Player. 安卓视频播放器,封装MediaPlayer、ExoPlayer、IjkPlayer。模仿抖音并实现预加载,列表播放,悬浮播放,广告播放,弹幕
Stars: ✭ 3,796 (+12989.66%)
Mutual labels:  player, video-player
Pbjvideoplayer
▶️ video player, simple way to play and stream media on iOS/tvOS
Stars: ✭ 620 (+2037.93%)
Mutual labels:  player, video-player
Giraffeplayer2
out of the box android video player(support lazy load, ListView/RecyclerView and hight performance)
Stars: ✭ 344 (+1086.21%)
Mutual labels:  player, video-player
Moonplayer
Video player that can play online videos from youtube, bilibili etc.
Stars: ✭ 399 (+1275.86%)
Mutual labels:  player, video-player
kaltura-player-js
Kaltura Player JS Platform - Cloud TV and OVP Media Players
Stars: ✭ 83 (+186.21%)
Mutual labels:  player, video-player
Rx Player
DASH/Smooth HTML5 Video Player
Stars: ✭ 600 (+1968.97%)
Mutual labels:  player, video-player
Clappr
🎬 An extensible media player for the web.
Stars: ✭ 5,436 (+18644.83%)
Mutual labels:  player, video-player
Mobileplayer Ios
📱 🎥 A powerful and completely customizable media player for iOS
Stars: ✭ 2,931 (+10006.9%)
Mutual labels:  player, video-player
Abplayerhtml5
Video Player for danmaku comments. ABPlayer in HTML5. ABPlayer核心构件以动态HTML编写的版本。向HTML5进发!HTML5弹幕播放器
Stars: ✭ 858 (+2858.62%)
Mutual labels:  player, video-player
KingPlayer
🎬 一个专注于 Android 视频播放器的基础库,无缝切换内核。(IjkPlayer、ExoPlayer、VlcPlayer、MediaPlayer)
Stars: ✭ 35 (+20.69%)
Mutual labels:  player, video-player
Qier Player
🎬 A lightweight and sophisticated React-based H5 video player / 简单易用的h5播放器
Stars: ✭ 360 (+1141.38%)
Mutual labels:  player, video-player
X1Player
iOS端封装的视频播放器.支持直播,录播视频的播放,支持常用的播放界面控制,类似于ijkplayer 优点是体积更小,使用快捷
Stars: ✭ 21 (-27.59%)
Mutual labels:  player, video-player
Vgplayer
📺 A simple iOS video player by Vein.
Stars: ✭ 383 (+1220.69%)
Mutual labels:  player, video-player
niki
Media Player, DLNA, Music, Video and Streaming
Stars: ✭ 14 (-51.72%)
Mutual labels:  player, video-player
clappr-core
Core components of the Clappr player architecture
Stars: ✭ 41 (+41.38%)
Mutual labels:  player, video-player
Playerdemo
一个视频播放器,开源版 potplayer ,用于总结播放器开发技术。
Stars: ✭ 491 (+1593.1%)
Mutual labels:  player, video-player
Yuview
The Free and Open Source Cross Platform YUV Viewer with an advanced analytics toolset
Stars: ✭ 665 (+2193.1%)
Mutual labels:  player, video-player

Dailymotion Swift Player SDK for iOS

Build Status Version License Swift Platform

Requirements

  • Xcode 8 and later
  • Swift 4
  • iOS 8+

Note: this SDK is using IDFA collection (will be asked by Apple in iTunes Connect when you will submit your app in the store). You can still disable it if you really need to when instantiating DMPlayerViewController.

Note: If you require an Objective-C version of the library or support for iOS < 8, use the old version of the library.

Installation

The preferred way is via CocoaPods. To install, add the following to your Podfile:

use_frameworks!

pod 'DailymotionPlayerSDK`

Usage

In the view controller that is going to serve videos, keep a reference to the Dailymotion player, and set your class as delegate:

import UIKit
import DailymotionPlayerSDK

class VideoViewController: UIViewController {

  // The player container. See setupPlayerViewController()
  @IBOutlet private var containerView: UIView!

  private lazy var playerViewController: DMPlayerViewController = {
    // If you have an OAuth token, you can pass it to the player to hook up
    // a user's view history.
    let parameters: [String: Any] = [
      "fullscreen-action": "trigger_event", // Trigger an event when the users toggles full screen mode in the player
      "sharing-action": "trigger_event" // Trigger an event to share the video to e.g. show a UIActivityViewController
    ]
    let controller = DMPlayerViewController(parameters: parameters)
    controller.delegate = self
    return controller
  }()

  override func viewDidLoad() {
    super.viewDidLoad()
    setupPlayerViewController()
  }

  // Add the player to your view. e.g. add a container on your storyboard
  // and add the player's view as subview to that
  private func setupPlayerViewController() {
    addChildViewController(playerViewController)

    let view = playerViewController.view!
    containerView.addSubview(view)
    view.translatesAutoresizingMaskIntoConstraints = false
    // Make the player's view fit our container view
    NSLayoutConstraint.activate([
      view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
      view.trailingAnchor.constraint(equalTo: containerView.trailingAnchor),
      view.topAnchor.constraint(equalTo: containerView.topAnchor),
      view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
    ])
  }

}

extension VideoViewController: DMPlayerViewControllerDelegate {

  // The delegate has 4 mandatory functions

  func player(_ player: DMPlayerViewController, didReceiveEvent event: PlayerEvent) {
    // Sends player events of either .namedEvent(name: String, data: [String: String]?), .timeEvent(name: String, time: Double) or .errorEvent(error: PlayerError)
  }

  func player(_ player: DMPlayerViewController, openUrl url: URL) {
    // Sent when a user taps on an ad that can display more information
  }

  func playerDidInitialize(_ player: DMPlayerViewController) {
    // Sent when the player has finished initializing
  }

  func player(_ player: DMPlayerViewController, didFailToInitializeWithError error: Error) {
    // Sent when the player failed to initialized
  }

}

For a full list of events, see the player API events page

To playback a video, call the player's load method with the video's id:

func loadVideo(withId id: String) {
  playerViewController.load(videoId: id)
}

For a list of parameters, see the player API parameters page.

To handle events sent by the player, let's implement the event delegate method mentioned above:

func player(_ player: DMPlayerViewController, didReceiveEvent event: PlayerEvent) {
  switch event {
    case .namedEvent(let name, _) where name == "fullscreen_toggle_requested":
      toggleFullScreen()
    default:
      break
  }
}

private func toggleFullScreen() {
  // Keep track of the orientation via an isPlayerFullscreen bool
  isPlayerFullscreen = !isPlayerFullscreen
  updateDeviceOrientation()
  updatePlayerSize()
}

private func updateDeviceOrientation() {
  let orientation: UIDeviceOrientation = isPlayerFullscreen ? .landscapeLeft : .portrait
  UIDevice.current.setValue(orientation.rawValue, forKey: #keyPath(UIDevice.orientation))
}

private func updatePlayerSize() {
  if isPlayerFullscreen {
    playerHeightConstraint.constant = nextSize.height
  } else {
    // Keep track of the initial player's height, e.g. via a didSet handler in the constraint outlet
    playerHeightConstraint.constant = initialPlayerHeight
  }
}

See the Example directory for a working sample of all this in action.

License

DailymotionPlayerSDK is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].