Skip to content

Commit

Permalink
fix(player): Expanded conditionals to test if media is HLS or Dash us…
Browse files Browse the repository at this point in the history
…ing also MIME types
  • Loading branch information
rafa8626 committed Jan 23, 2019
1 parent 2d98ac2 commit d9c489e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
20 changes: 10 additions & 10 deletions dist/openplayer.js
Expand Up @@ -345,7 +345,7 @@ exports.offset = offset;
/* 6 */
/***/ (function(module, exports) {

var core = module.exports = { version: '2.5.7' };
var core = module.exports = { version: '2.6.2' };
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef


Expand Down Expand Up @@ -875,14 +875,14 @@ function getExtension(url) {

exports.getExtension = getExtension;

function isHlsSource(url) {
return /\.m3u8/i.test(url);
function isHlsSource(media) {
return /\.m3u8/i.test(media.src) || ['application/x-mpegURL', 'application/vnd.apple.mpegurl'].indexOf(media.type) > -1;
}

exports.isHlsSource = isHlsSource;

function isDashSource(url) {
return /\.mpd/i.test(url);
function isDashSource(media) {
return /\.mpd/i.test(media.src) || media.type === 'application/dash+xml';
}

exports.isDashSource = isDashSource;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ var store = global[SHARED] || (global[SHARED] = {});
})('versions', []).push({
version: core.version,
mode: __webpack_require__(25) ? 'pure' : 'global',
copyright: 2018 Denis Pushkarev (zloirock.ru)'
copyright: 2019 Denis Pushkarev (zloirock.ru)'
});


Expand Down Expand Up @@ -6607,10 +6607,10 @@ var Media = function () {
} else {
return new html5_1.default(this.element, media);
}
} else if (source.isHlsSource(media.src)) {
} else if (source.isHlsSource(media)) {
var hlsOptions = this.options && this.options.hls ? this.options.hls : undefined;
return new hls_1.default(this.element, media, this.autoplay, hlsOptions);
} else if (source.isDashSource(media.src)) {
} else if (source.isDashSource(media)) {
var dashOptions = this.options && this.options.dash ? this.options.dash : undefined;
return new dash_1.default(this.element, media, dashOptions);
}
Expand Down Expand Up @@ -6846,7 +6846,7 @@ var DashMedia = function (_native_1$default) {
set: function set(media) {
var _this4 = this;

if (media_1.isDashSource(media.src)) {
if (media_1.isDashSource(media)) {
this._revoke();

this.player = dashjs.MediaPlayer().create();
Expand Down Expand Up @@ -7115,7 +7115,7 @@ var HlsMedia = function (_native_1$default) {
set: function set(media) {
var _this5 = this;

if (media_1.isHlsSource(media.src)) {
if (media_1.isHlsSource(media)) {
this._revoke();

this.player = new Hls(this.options);
Expand Down
2 changes: 1 addition & 1 deletion dist/openplayer.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/js/media.ts
Expand Up @@ -438,10 +438,10 @@ class Media {
} else {
return new HTML5Media(this.element, media);
}
} else if (source.isHlsSource(media.src)) {
} else if (source.isHlsSource(media)) {
const hlsOptions = this.options && this.options.hls ? this.options.hls : undefined;
return new HlsMedia(this.element, media, this.autoplay, hlsOptions);
} else if (source.isDashSource(media.src)) {
} else if (source.isDashSource(media)) {
const dashOptions = this.options && this.options.dash ? this.options.dash : undefined;
return new DashMedia(this.element, media, dashOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/media/dash.ts
Expand Up @@ -106,7 +106,7 @@ class DashMedia extends Native {
* @memberof DashMedia
*/
set src(media: Source) {
if (isDashSource(media.src)) {
if (isDashSource(media)) {
this._revoke();
this.player = dashjs.MediaPlayer().create();
this._preparePlayer();
Expand Down
2 changes: 1 addition & 1 deletion src/js/media/hls.ts
Expand Up @@ -136,7 +136,7 @@ class HlsMedia extends Native {
* @memberof HlsMedia
*/
set src(media: Source) {
if (isHlsSource(media.src)) {
if (isHlsSource(media)) {
this._revoke();
this.player = new Hls(this.options);
this.player.loadSource(media.src);
Expand Down
14 changes: 8 additions & 6 deletions src/js/utils/media.ts
@@ -1,3 +1,5 @@
import Source from '../interfaces/source';

/**
* Get media file extension from a URL.
*
Expand All @@ -19,22 +21,22 @@ export function getExtension(url: string): string {
* Check if URL is an HLS element.
*
* @export
* @param {string} url The target URL.
* @param {Source} media The target media, including URL and type.
* @returns {boolean}
*/
export function isHlsSource(url: string): boolean {
return /\.m3u8/i.test(url);
export function isHlsSource(media: Source): boolean {
return /\.m3u8/i.test(media.src) || ['application/x-mpegURL', 'application/vnd.apple.mpegurl'].indexOf(media.type) > -1;
}

/**
* Check if URL is an MPEG-DASH element.
*
* @export
* @param {string} url The target URL.
* @param {Source} media The target media, including URL and type.
* @returns {boolean}
*/
export function isDashSource(url: string): boolean {
return /\.mpd/i.test(url);
export function isDashSource(media: Source): boolean {
return /\.mpd/i.test(media.src) || media.type === 'application/dash+xml';
}

/**
Expand Down

0 comments on commit d9c489e

Please sign in to comment.