Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test Only] Support playing another source without refreshing test page. #137

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added tools/PlaybackService/src/wwwroot/favicon.ico
Binary file not shown.
12 changes: 9 additions & 3 deletions tools/PlaybackService/src/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
width: 1290px;
}

video {
.video-container {
width: 100%;
height: 360px;
background-color: black;

& video {
width: 100%;
height: 100%;
}
}

.input {
Expand Down Expand Up @@ -64,12 +70,12 @@ <h1>PlaybackService Test Page</h1>
<div class="player-container">
<div class="player">
<h4>Dash Player</h4>
<video id="dashvideo" controls></video>
<div class="video-container" id="dashvideo-container"></div>
<label id="dash-error" class="error"></label>
</div>
<div class="player">
<h4>Shaka Player</h4>
<video id="shakavideo" controls></video>
<div class="video-container" id="shakavideo-container"></div>
<label id="shaka-error" class="error"></label>
</div>
</div>
Expand Down
38 changes: 28 additions & 10 deletions tools/PlaybackService/src/wwwroot/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
async function dashinit() {
const video = document.querySelector("video")
video.pendingSessionData = []
video.addEventListener('encrypted', handleEncryption(video))
const player = dashjs.MediaPlayer().create()
player.initialize(video, video.src, true)
}

function play() {
removePlayers();

showError("error", "");
showError("dash-error", "");
showError("shaka-error", "");
Expand Down Expand Up @@ -43,7 +37,7 @@ function play() {
}

function dashPlay(playUri) {
var video = document.getElementById("dashvideo");
var video = createVideoElement(document.getElementById("dashvideo-container"));
var player = dashjs.MediaPlayer().create();
player.initialize(video, playUri, true);
player.on("error", (e) => {
Expand All @@ -66,7 +60,7 @@ function dashPlay(playUri) {
}

async function shakaPlay(playUri) {
var video = document.getElementById("shakavideo");
var video = createVideoElement(document.getElementById("shakavideo-container"));
var player = new shaka.Player(video);
player.addEventListener("error", (e) => {
console.log("shaka-error");
Expand Down Expand Up @@ -96,3 +90,27 @@ function showError(domId, msg) {
var errorDom = document.getElementById(domId);
errorDom.innerHTML = `<i>${msg}</i>`;
}

function removePlayers()
{
var videos = document.getElementsByTagName("video");
while (videos.length) {
videos[videos.length - 1].remove();
}
}

function clearVideoElement(parent)
{
while (parent.firstChild) {
parent.removeChild(parent.lastChild);
}
}

function createVideoElement(parent)
{
var video = document.createElement('video');
video.setAttribute("controls", "controls");
video.setAttribute("autoplay", "autoplay");
parent.appendChild(video);
return video;
}
Loading