How to use the xgplayer.util function in xgplayer

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.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-hls.js / src / index.js View on Github external
constructor (options) {
    super(options)
    this.hlsOpts = options.hlsOpts || {}
    let util = Player.util
    let player = this
    this.browser = utils.getBrowserVersion()
    if(player.config.useHls === undefined) {
      if ((Player.sniffer.device === 'mobile' && navigator.platform !== 'MacIntel' && navigator.platform !== 'Win32') || this.browser.indexOf('Safari') > -1) {
        return
      }
    } else if(!player.config.useHls) {
      return
    }

    let hls
    hls = new Hls(this.hlsOpts)
    this.hls = hls

    Object.defineProperty(player, 'src', {
      get () {
github bytedance / xgplayer / packages / xgplayer-music / src / music.js View on Github external
import Player from 'xgplayer'
import Lyric from './lyric'
import Analyze from './analyze'
import Xhr from './xhr'
let mode
let timeScale = 15

const util = Player.util

class Music extends Player {
  constructor (options) {
    let opts = util.deepCopy({
      controls: true,
      mediaType: 'audio',
      ignores: ['fullscreen', 'start', 'definition', 'makeBullet', 'textTrack', 'loading', 'pc', 'mobile', 'playbackRate', 'replay', 'error', 'poster']
    }, options)
    if (!opts.volumeShow) {
      opts.ignores.push('volume')
    }
    super(opts)
    let player = this
    this.rawConfig = options
    this.list = util.typeOf(opts.url) === 'Array' ? opts.url : [{
      src: opts.url,
github bytedance / xgplayer / packages / xgplayer-flv-live / src / mobile.js View on Github external
addLiveFlag () {
    const player = this;
    Player.util.addClass(player.root, 'xgplayer-is-live')
    if (!Player.util.findDom(this.root, 'xg-live')) {
      const live = Player.util.createDom('xg-live', '正在直播', {}, 'xgplayer-live')
      player.controls.appendChild(live)
    }
  }
github bytedance / xgplayer / packages / xgplayer-flv-live / src / index.js View on Github external
flv.once(EVENTS.REMUX_EVENTS.INIT_SEGMENT, () => {
      Player.util.addClass(player.root, 'xgplayer-is-live')
      if (!Player.util.findDom(this.root, 'xg-live')) {
        const live = Player.util.createDom('xg-live', '正在直播', {}, 'xgplayer-live')
        player.controls.appendChild(live)
      }
    })
github bytedance / xgplayer / packages / xgplayer-hls.js / src / index.js View on Github external
this.once('complete', () => {
      hls.attachMedia(player.video)
      player.once('canplay', () => {
        player.play()
      })
      if(player.config.isLive) {
        Player.util.addClass(player.root, 'xgplayer-is-live')
        const live = Player.util.createDom('xg-live', '正在直播', {}, 'xgplayer-live')
        player.controls.appendChild(live)
      }
    })
    this.once('destroy', () => {

xgplayer

video player

MIT
Latest version published 1 day ago

Package Health Score

84 / 100
Full package analysis