I am updating my code from Soundcloud Javascript API v. 1 to the very last. I was able to transfer 90% of the code, but I have strange behavior when I try to stream some track. I think I applied all the necessary listeners to the player object, but I cannot figure out where the problem is. Here is a snippet of my code:
try {
SC.stream( "/tracks/" + playlist[ now_playing ].sndc_id ).then(
function (player) {
sound_object = player;
sound_object.on(
'state-change',
function() {
console.log('state-change', this.controller._state);
}
).on(
'play',
function() {
console.log('play');
}
).on(
'play-start',
function() {
console.log('playback started');
playing = true;
show();
play();
updateInfo();
}
).on(
'buffering_start',
function() {
console.log('buffering starts');
}
).on(
'buffering_end',
function() {
console.log('buffering ends');
}
).on(
'time',
function() {
console.log( this.currentTime() );
updateProgress(this.currentTime(), playlist[ now_playing ].duration);
}
).on(
'finish',
function() {
console.log('finish');
loadNext();
}
).on(
'pause',
function() {
console.log('pause');
}
).on(
'play-resume',
function() {
console.log('play-resume');
}
).on(
'geo_blocked',
function() {
console.log('geo_blocked');
loadNext();
}
).on(
'audio_error',
function() {
console.log('audio_error');
sendErrorReport(playlist[ now_playing ].id);
loadNext();
}
).on(
'no_streams',
function() {
console.log('no_streams');
sendErrorReport(playlist[ now_playing ].id);
loadNext();
}
).on(
'no_protocol',
function() {
console.log('no_protocol');
loadNext();
}
).on(
'no_connection',
function() {
console.log('no_connection');
loadNext();
}
);
sound_object.play();
},
function( e ) {
console.log( e );
loadNext();
}
);
} catch(e) {
console.log( e );
loadNext();
}
The array playlist
contains a list of valid path identifiers. What am I doing:
- start streaming
- after starting playback, displays information about the current track
- during playback, update the progress bar
The first thing I noticed was that this new API is much slower than the previous ones; the second strange thing is that events do not fire in the order I would expect:
play
buffer-start
play-start
buffer-end
finish
play-start
buffer-start
, , .
- Javascript, SoundCloud JS , try {} catch {}, JS:
play (index):692
(5x) state-change initialize (index):711
(8x) buffering starts
(3x) sdk-3.0.0.js:12
Uncaught Error: Error: An invalid exception was thrown.
i.setVolume @ sdk-3.0.0.js:12
i.createAudioPlayer @ sdk-3.0.0.js:8
o @ sdk-3.0.0.js:13
(anonymous function) @ sdk-3.0.0.js:13
(anonymous function) @ sdk-3.0.0.js:18
p @ sdk-3.0.0.js:13
d.fireWith @ sdk-3.0.0.js:13
d.fire @ sdk-3.0.0.js:13
(anonymous function) @ sdk-3.0.0.js:13
(anonymous function) @ sdk-3.0.0.js:18
p @ sdk-3.0.0.js:13
d.fireWith @ sdk-3.0.0.js:13
d.fire @ sdk-3.0.0.js:13
u.onreadystatechange @ sdk-3.0.0.js:13
SDK , , .
, - , . , , (, 404 ), .
, S.