features.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  3. *
  4. * @author zheng qian <xqq@xqq.im>
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import IOController from '../io/io-controller.js';
  19. import {createDefaultConfig} from '../config.js';
  20. class Features {
  21. static supportMSEH264Playback() {
  22. return window.MediaSource &&
  23. window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"');
  24. }
  25. static supportNetworkStreamIO() {
  26. let ioctl = new IOController({}, createDefaultConfig());
  27. let loaderType = ioctl.loaderType;
  28. ioctl.destroy();
  29. return loaderType == 'fetch-stream-loader' || loaderType == 'xhr-moz-chunked-loader';
  30. }
  31. static getNetworkLoaderTypeName() {
  32. let ioctl = new IOController({}, createDefaultConfig());
  33. let loaderType = ioctl.loaderType;
  34. ioctl.destroy();
  35. return loaderType;
  36. }
  37. static supportNativeMediaPlayback(mimeType) {
  38. if (Features.videoElement == undefined) {
  39. Features.videoElement = window.document.createElement('video');
  40. }
  41. let canPlay = Features.videoElement.canPlayType(mimeType);
  42. return canPlay === 'probably' || canPlay == 'maybe';
  43. }
  44. static getFeatureList() {
  45. let features = {
  46. mseFlvPlayback: false,
  47. mseLiveFlvPlayback: false,
  48. networkStreamIO: false,
  49. networkLoaderName: '',
  50. nativeMP4H264Playback: false,
  51. nativeWebmVP8Playback: false,
  52. nativeWebmVP9Playback: false
  53. };
  54. features.mseFlvPlayback = Features.supportMSEH264Playback();
  55. features.networkStreamIO = Features.supportNetworkStreamIO();
  56. features.networkLoaderName = Features.getNetworkLoaderTypeName();
  57. features.mseLiveFlvPlayback = features.mseFlvPlayback && features.networkStreamIO;
  58. features.nativeMP4H264Playback = Features.supportNativeMediaPlayback('video/mp4; codecs="avc1.42001E, mp4a.40.2"');
  59. features.nativeWebmVP8Playback = Features.supportNativeMediaPlayback('video/webm; codecs="vp8.0, vorbis"');
  60. features.nativeWebmVP9Playback = Features.supportNativeMediaPlayback('video/webm; codecs="vp9"');
  61. return features;
  62. }
  63. }
  64. export default Features;