Skip to content

Commit

Permalink
Add async to example code
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Nov 14, 2023
1 parent 2a21c71 commit d18a0c2
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions media-source-respec.html
Original file line number Diff line number Diff line change
Expand Up @@ -3084,13 +3084,13 @@ <h2>Examples</h2>

sourceBuffer.appendBuffer(initSegment);
} catch (error) {
// Handle errors that might occur during the initialization segment fetching
// Handle errors that might occur during initialization segment fetching.
console.error("Error fetching initialization segment:", error);
mediaSource.endOfStream("network");
}
}

function appendNextMediaSegment(mediaSource) {
async function appendNextMediaSegment(mediaSource) {
if (
mediaSource.readyState === "closed" ||
mediaSource.sourceBuffers[0].updating
Expand All @@ -3103,17 +3103,19 @@ <h2>Examples</h2>
return;
}

const mediaSegment = getNextMediaSegment();
try {
const mediaSegment = await getNextMediaSegment();

if (!mediaSegment) {
// NOTE: If mediaSource.readyState == "ended", this appendBuffer() call will
// cause mediaSource.readyState to transition to "open". The web application
// should be prepared to handle multiple "sourceopen" events.
mediaSource.sourceBuffers[0].appendBuffer(mediaSegment);
}
catch (error) {
// Handle errors that might occur during media segment fetching.
console.error("Error fetching media segment:", error);
mediaSource.endOfStream("network");
return;
}

// NOTE: If mediaSource.readyState == "ended", this appendBuffer() call will
// cause mediaSource.readyState to transition to "open". The web application
// should be prepared to handle multiple "sourceopen" events.
mediaSource.sourceBuffers[0].appendBuffer(mediaSegment);
}

function onSeeking(mediaSource, video) {
Expand Down Expand Up @@ -3147,7 +3149,7 @@ <h2>Examples</h2>
}

// Example function for getting the next media segment
function getNextMediaSegment() {
async function getNextMediaSegment() {
// Implement fetching of the next media segment
// This is just a placeholder function
}
Expand Down

0 comments on commit d18a0c2

Please sign in to comment.