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

Sniffer

使用

// npm方式
import { Sniffer } from 'xgplayer'

// cdn方式
const Sniffer = window.Player.Sniffer

device

  • @desc:设备类型
  • @valuepc | mobile

os

  • @desc:系统类型
{
  isTablet:  Boolean,
  isPhone:  Boolean,
  isIpad:  Boolean,
  isIos:  Boolean,
  isAndroid:  Boolean,
  isPc:  Boolean,
  isSymbian:  Boolean,
  isWindowsPhone:  Boolean,
  isFireFox:  Boolean
}

browser

  • @desc:浏览器类型

  • @valueie | firefox | chrome | safari

isWeixin

  • @desc:是否是微信
  • @valuefalse | true

probeConfigSupported

利用 MediaCapabilities.decodingInfo() 探测浏览器解码支持程度

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

当前环境是否支持hevc解码,isHevcSupported的校验依赖MediaSource.isTypeSupported的校验,目前校验了四个codec, 具体如下:

      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"')

调用

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

isSupportMP4

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

校验当前浏览器环境是否支持mp4视频的解码播放, 校验的codec列表如下:

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'
]

调用

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