Skip to content

Commit

Permalink
MPEG DASH support
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Sep 25, 2017
1 parent d8cfa12 commit c0f515a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"require": false,
"module": false,
"Hls": false,
"flvjs": false
"flvjs": false,
"dashjs": false
}
}
21 changes: 21 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="stylesheet" href="demo.css">
<script src="https://unpkg.com/flv.js/dist/flv.min.js"></script>
<script src="https://unpkg.com/hls.js/dist/hls.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dashjs/dist/dash.all.min.js"></script>
<script src="DPlayer.js"></script>
</head>

Expand Down Expand Up @@ -215,6 +216,26 @@ <h2 id="flv-support">FLV support</h2>
flvPlayer.load();
</script>
</div>
<h2 id="dash-support">MPEG DASH support</h2>
<div class="example">
<div id="dplayer10"></div>
<script>
var dp10 = new DPlayer({
container: document.getElementById('dplayer10'),
video: {
url: 'http://devtest.qiniudn.com/若能绽放光芒.mpd',
type: 'dash'
}
});
</script>
<div id="dplayer11"></div>
<script>
var dp11 = new DPlayer({
container: document.getElementById('dplayer11')
});
dashjs.MediaPlayer().create().initialize(dp11.video, "http://devtest.qiniudn.com/若能绽放光芒.mpd", false);
</script>
</div>

<h2 id="bilibili-video-and-danmaku">Bilibili video and danmaku</h2>
<div class="example">
Expand Down
2 changes: 1 addition & 1 deletion dist/DPlayer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/DPlayer.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dplayer",
"version": "1.15.1",
"version": "1.16.0",
"description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css",
Expand Down
16 changes: 12 additions & 4 deletions src/DPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,28 +951,36 @@ class DPlayer {
else if (/.flv(#|\?|$)/i.exec(video.src)) {
this.type = 'flv';
}
else if (/.mpd(#|\?|$)/i.exec(video.src)) {
this.type = 'dash';
}
else {
this.type = 'normal';
}
}

// Support HTTP Live Streaming
if (this.type === 'hls' && Hls.isSupported()) {
// HTTP Live Streaming
if (this.type === 'hls' && Hls && Hls.isSupported()) {
// this.container.getElementsByClassName('dplayer-time')[0].style.display = 'none';
const hls = new Hls();
hls.loadSource(video.src);
hls.attachMedia(video);
}

// Support FLV
if (this.type === 'flv' && flvjs.isSupported()) {
// FLV
if (this.type === 'flv' && flvjs && flvjs.isSupported()) {
const flvPlayer = flvjs.createPlayer({
type: 'flv',
url: video.src
});
flvPlayer.attachMediaElement(video);
flvPlayer.load();
}

// MPEG DASH
if (this.type === 'dash' && dashjs) {
dashjs.MediaPlayer().create().initialize(video, video.src, false);
}
}

initVideo (video, type) {
Expand Down

0 comments on commit c0f515a

Please sign in to comment.