西瓜播放器 HTML5 video video.js 播放器 HTML5播放器 mp4 hls hls.js flv flv.js dash dash.js 无缝切换

Sniffer

Usage

// Npm
import { Sniffer } from 'xgplayer'

// CDN
const Sniffer = window.Player.Sniffer

const device = Sniffer.device

device

  • @desc: Device type
  • @value: pc | mobile |tablet

os

  • @desc: Platorm type
{
  isTablet:  Boolean,
  isPhone:  Boolean,
  isIpad:  Boolean,
  isIos:  Boolean,
  isAndroid:  Boolean,
  isPc:  Boolean,
  isSymbian:  Boolean,
  isWindowsPhone:  Boolean,
  isFireFox:  Boolean
}

browser

  • @desc: Brand of browser

  • @value: ie | firefox | chrome | safari

isWeixin

  • @desc: Running in Wechat app
  • @value: false | true

probeConfigSupported

use MediaCapabilities.decodingInfo() detect browser decoding support

const mediaConfig = {
  type: 'file', // or 'media-source' or 'webrtc'
  video: {
    contentType: 'video/mp4;codecs="avc1.4d0028"', // AVC Main, Level 4
    width: 800, // width of the video
    height: 600, // height of the video
    bitrate: 10000, // number of bits used to encode 1s of video
    framerate: 30 // number of frames making up that 1s.
  },
  audio: {
    contentType: 'audio/ogg; codecs=vorbis', // valid content type
    channels: 2, // audio channels used by the track
    bitrate: 132700, // number of bits used to encode 1s of audio
    samplerate: 5200 // number of audio samples making up that 1s.
  }
}

Sniffer.probeConfigSupported(mediaConfig).then((decodingInfo) => {
  console.log(decodingInfo)
})

isHevcSupported

  • @param null
  • @return boolean

Whether the current environment supports hevc decoding, the verification of isHevcSupported depends onMediaSource.isTypeSupported。 The verification of the four codecs is currently verified, as follows:

      MediaSource.isTypeSupported('video/mp4;codecs="hev1.1.6.L120.90"') ||
      MediaSource.isTypeSupported('video/mp4;codecs="hev1.2.4.L120.90"') ||
      MediaSource.isTypeSupported('video/mp4;codecs="hev1.3.E.L120.90"') ||
      MediaSource.isTypeSupported('video/mp4;codecs="hev1.4.10.L120.90"')

demo

import { Sniffer } from 'xgplayer'
const result = Sniffer.isHevcSupported()

isSupportMP4

  • @param null
  • @return { isSupport: boolean, mime: string }

Check whether the current browser environment supports the decoding and playback of mp4 videos. The codec list for checking is as follows:

const H264_MIMETYPES = [
  'avc1.42E01E, mp4a.40.2',
  'avc1.58A01E, mp4a.40.2',
  'avc1.4D401E, mp4a.40.2',
  'avc1.64001E, mp4a.40.2',
  'avc1.42E01E',
  'mp4v.20.8',
  'avc1.42E01E, mp4a.40.2',
  'avc1.58A01E, mp4a.40.2',
  'avc1.4D401E, mp4a.40.2',
  'avc1.64001E, mp4a.40.2',
  'mp4v.20.8, mp4a.40.2',
  'mp4v.20.240, mp4a.40.2'
]

demo

// 该API也可以通过Sniffer工具类调用
import { Sniffer } from 'xgplayer'
const result = Sniffer.isSupportMP4()