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

Changed .play to a promise function #269

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<title>Ongaku : Anime Radio</title>

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
Expand All @@ -15,7 +16,7 @@

<body>

<audio id = "music"></audio>
<audio id = "music" allow="autoplay"></audio>

<div id="modal-wrapper">
<div id="track-list" class="track-list">
Expand Down
34 changes: 32 additions & 2 deletions js/ongaku.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,22 @@
// function to play tracks
function play (order) {
music.src = order[0].link;
music.play();
music.crossOrigin = 'anonymous';
var playPromise = music.play();

// In browsers that don’t yet support this functionality,
// playPromise won’t be defined.
if (playPromise !== undefined) {
playPromise.then(function() {
// Automatic playback started!
console.log("playing");
}).catch(function(error) {
// Automatic playback failed.
// Show a UI element to let the user manually start playback.
console.log(error);
});
}

displayTrackName();
displayStar();
document.body.style.backgroundImage = "url('" + order[0].img + "')";
Expand Down Expand Up @@ -366,7 +381,22 @@

//updating the player to play the selected track
music.src = found_title[0].link;
music.play();
//music.play();
music.crossOrigin = 'anonymous';
var playPromise = music.play();

// In browsers that don’t yet support this functionality,
// playPromise won’t be defined.
if (playPromise !== undefined) {
playPromise.then(function() {
// Automatic playback started!
console.log("playing");
}).catch(function(error) {
// Automatic playback failed.
// Show a UI element to let the user manually start playback.
console.log(error);
});
}

//displays status of Favourite
displayStar();
Expand Down