import { LoaderResource } from "pixi.js" ; import { Log } from "../log/Log" ; export class VideoLoader { private static suffix : string [ ] = [ "mp4" , "webm" , "avi" , "rmvb" ] ; public static use ( resource , next ) { if ( resource . extension && VideoLoader . suffix . includes ( resource . extension ) ) { let video = resource . data ; video . id = resource . name + "-" + VideoLoader . guid ( ) ; video . preload = "auto" ; video . setAttribute ( "src" , resource . url ) ; video . setAttribute ( "webkit-playsinline" , "" ) ; video . setAttribute ( "playsinline" , "" ) ; video . setAttribute ( "x5-playsinline" , "" ) ; video . setAttribute ( "x5-video-player-type" , "h5" ) ; video . setAttribute ( "x-webkit-airplay" , "allow" ) ; let callback = function ( ) { Log . info ( "heheheheheeh" , "加载完成" ) ; video . removeEventListener ( "canplaythrough" , callback ) ; next ( ) ; } ; video . addEventListener ( "canplaythrough" , callback ) ; video . load ( ) ; } else { next ( ) ; } } private static loadCss ( ) { return { } ; } private static guid ( ) { return "xxxxxxxx-xxxx" . replace ( /[xy]/g , function ( c ) { var r = ( Math . random ( ) * 16 ) | 0 , v = c == "x" ? r : ( r & 0x3 ) | 0x8 ; return v . toString ( 16 ) ; } ) ; } }