flv.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Polyfill from './utils/polyfill.js';
  19. import Features from './core/features.js';
  20. import {BaseLoader, LoaderStatus, LoaderErrors} from './io/loader.js';
  21. import FlvPlayer from './player/flv-player.js';
  22. import NativePlayer from './player/native-player.js';
  23. import PlayerEvents from './player/player-events.js';
  24. import {ErrorTypes, ErrorDetails} from './player/player-errors.js';
  25. import LoggingControl from './utils/logging-control.js';
  26. import {InvalidArgumentException} from './utils/exception.js';
  27. // here are all the interfaces
  28. // install polyfills
  29. Polyfill.install();
  30. // factory method
  31. function createPlayer(mediaDataSource, optionalConfig) {
  32. let mds = mediaDataSource;
  33. if (mds == null || typeof mds !== 'object') {
  34. throw new InvalidArgumentException('MediaDataSource must be an javascript object!');
  35. }
  36. if (!mds.hasOwnProperty('type')) {
  37. throw new InvalidArgumentException('MediaDataSource must has type field to indicate video file type!');
  38. }
  39. switch (mds.type) {
  40. case 'flv':
  41. return new FlvPlayer(mds, optionalConfig);
  42. default:
  43. return new NativePlayer(mds, optionalConfig);
  44. }
  45. }
  46. // feature detection
  47. function isSupported() {
  48. return Features.supportMSEH264Playback();
  49. }
  50. function getFeatureList() {
  51. return Features.getFeatureList();
  52. }
  53. // interfaces
  54. let flvjs = {};
  55. flvjs.createPlayer = createPlayer;
  56. flvjs.isSupported = isSupported;
  57. flvjs.getFeatureList = getFeatureList;
  58. flvjs.BaseLoader = BaseLoader;
  59. flvjs.LoaderStatus = LoaderStatus;
  60. flvjs.LoaderErrors = LoaderErrors;
  61. flvjs.Events = PlayerEvents;
  62. flvjs.ErrorTypes = ErrorTypes;
  63. flvjs.ErrorDetails = ErrorDetails;
  64. flvjs.FlvPlayer = FlvPlayer;
  65. flvjs.NativePlayer = NativePlayer;
  66. flvjs.LoggingControl = LoggingControl;
  67. Object.defineProperty(flvjs, 'version', {
  68. enumerable: true,
  69. get: function () {
  70. // replace by webpack.DefinePlugin
  71. return __VERSION__;
  72. }
  73. });
  74. export default flvjs;