How to use xgplayer - 10 common examples

To help you get started, we’ve selected a few xgplayer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bytedance / xgplayer / packages / xgplayer-music / src / template / Template.js View on Github external
render () {
    // console.log('[template]render:')
    if (!this.template) {
      throw new Error('未设置template')
    }
    const compiled = compile(this.template, this.options)

    // console.log('[template]compiled:', compiled)

    const astCompiler = new ASTCompiler(this.element, compiled, this.model, {
      inject: {
        $player: this.player, // 注入$player对象
        $util: Player.util // 注入$util对象
      }
    })
    // const mvvm = new MVVM({
    //   el: this.element,
    //   data: this.model.data,
    //   mounted: this.model.mounted,
    //   methods: this.model.methods,
    //   templateDescriptor: compiled
    // })

    // 插入template的css
    // TODO: 考虑会影响其他样式,考虑加入scoped
    const style = insertCss(this.style)
    // console.log('[template]css injected:', compiled)
  }
}
github bytedance / xgplayer / packages / xgplayer-flv-vod / src / flv-vod.js View on Github external
this.loader.load(this._player.config.url).catch(() => {
      // 在尝试获取视频数据失败时,尝试使用直播方式加载整个视频
      this._player.emit('error', new Player.Errors('network', this._player.config.url))
    })
  }
github bytedance / xgplayer / packages / xgplayer-shaka / src / index.js View on Github external
constructor (options) {
    super(options)
    let self = this
    this.shakaOpts = options.shakaOpts || {}
    this.util = Player.util
    this.player = this
    this.url = this.player.config.url
    this.sniffer = Player.sniffer
    this.player_ = null
    this.content = []

    Shaka.polyfill.installAll()

    if (Shaka.Player.isBrowserSupported()) {
      this.video_ = this.player.video
      this.video_.autoplay = false
      this.player_ = new Shaka.Player(this.video_)

      this.player_.addEventListener('error', function (event) {
        console.error('Error code', event.detail.code, 'object', event.detail) // eslint-disable-line no-console
      })

      if (this.shakaOpts) {
        this.player_.configure(this.shakaOpts)
github bytedance / xgplayer / packages / xgplayer-music / src / template / index.js View on Github external
import Player from 'xgplayer'
import Template from './Template'
import learningTemplate from '../templateExamples/learning'

const templatePlugin = function (player) {
  // TODO: 模版可配置化
  // TODO: 异步加载模版
  // TODO: 组件化机制
  const template = new Template(`#${player.config.id}`, learningTemplate, this)
  template.render()
}

Player.install('template', templatePlugin)
github bytedance / xgplayer / packages / xgplayer-mp4 / src / index.js View on Github external
let mp4player = function () {
  let player = this; let sniffer = Player.sniffer; let util = Player.util
  let Errors = Player.Errors; let mainURL; let backupURL
  let preloadTime = player.config.preloadTime || 15
  let waiterTimer
  let url = player.config.url
  let rule = player.config.pluginRule || function () { return true }
  if (!url) {
    player.emit('error', new Errors('other', player.config.vid))
    return
  }
  if (util.typeOf(url) === 'String') {
    mainURL = url
  } else if (util.typeOf(url) === 'Array' && url.length) {
    mainURL = url[0].src
    backupURL = url[1].src
  }
  player.config._mainURL = mainURL
github bytedance / xgplayer / packages / xgplayer-flv.js / src / index.js View on Github external
createInstance (flv) {
    const player = this
    const util = Player.util
    flv.attachMediaElement(player.video)
    flv.load()
    flv.play()
    if (this.flvOpts.isLive) {
      util.addClass(player.root, 'xgplayer-is-live')
      const live = util.createDom('xg-live', '正在直播', {}, 'xgplayer-live')
      player.controls.appendChild(live)
    }
    flv.on(Flv.Events.ERROR, (e) => {
      player.emit('error', new Player.Errors('other', player.config.url))
    })

    player.once('destroy', () => {
      flv.destroy()
      player.__flv__ = null
    })
github bytedance / xgplayer / packages / xgplayer-music / src / lyric.js View on Github external
show () {
    let dom = this.dom
    let lyrbicTxts = []
    let self = this
    const ev = ['click', 'touchstart']
    if (dom && dom.nodeType === 1) {
      const lrcWrap = Player.util.createDom('div', `<div></div>`, {}, 'xgplayer-lrcWrap')
      dom.appendChild(lrcWrap)
      this.list.forEach(item =&gt; {
        lyrbicTxts.push(`${item.lyric.replace(/[\r\n]/g, '')}`)
      })
      lrcWrap.innerHTML = lyrbicTxts.join('')
      const lrcForward = Player.util.createDom('xg-lrcForward', `<div></div>`, {}, 'xgplayer-lrcForward')
      dom.appendChild(lrcForward)
      ev.forEach(item =&gt; {
        lrcForward.addEventListener(item, function (e) {
          e.preventDefault()
          e.stopPropagation()
          self.offset -= self.offsetScale
          console.log(`lyric go forward ${self.offsetScale}s`)
        }, false)
      })

      const lrcBack = Player.util.createDom('xg-lrcBack', `<div></div>`, {}, 'xgplayer-lrcBack')
      dom.appendChild(lrcBack)
      ev.forEach(item =&gt; {
        lrcBack.addEventListener(item, function (e) {
          e.preventDefault()
          e.stopPropagation()
github bytedance / xgplayer / packages / xgplayer-flv.js / src / index.js View on Github external
flv.on(Flv.Events.ERROR, (e) => {
      player.emit('error', new Player.Errors('other', player.config.url))
    })
github bytedance / xgplayer / packages / xgplayer-flv-live / src / flv-live-mobile.js View on Github external
_handleDemuxError () {
    this._player.emit('error', new Player.Errors('parse', this._player.config.url))
  }
github bytedance / xgplayer / packages / xgplayer-hls-vod / src / index.js View on Github external
this.__core__.once(HLS_EVENTS.RETRY_TIME_EXCEEDED, () => {
      this.emit('error', new Player.Errors('network', this.config.url))
    })

xgplayer

video player

MIT
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis