user3327457
user3327457

Reputation:

JavaScript - music player with playlist

I'm trying to get a music playlist to work in JavaScript, however I cannot get it to change songs. Here is the fiddle, if someone could tell me what I am doing wrong I would be very grateful. I am using this code for changing song:

var newSong = songs[counter];
var player = document.getElementById('audio');
player.setAttribute('src', newSong);
player.load();
player.play();

Upvotes: 0

Views: 1734

Answers (1)

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

You code works fine nothing wrong with it.

You just forgot to set No wrap-in <body> option in fiddle see screenshot below.

enter image description here

var songs = ['http://www.tonycuffe.com/mp3/tail%20toddle.mp3', 'http://www.tonycuffe.com/mp3/cairnomount.mp3', 'http://www.tonycuffe.com/mp3/pipers%20hut.mp3'];

Fiddle

Upvotes: 2

Related Questions