Javascript 如果没有自动启动,则无法播放SoundCloud API
这段代码用于播放/暂停歌曲,但我无法让它在页面加载时停止自动播放Javascript 如果没有自动启动,则无法播放SoundCloud API,javascript,api,soundcloud,Javascript,Api,Soundcloud,这段代码用于播放/暂停歌曲,但我无法让它在页面加载时停止自动播放 function play_pause() { SC.stream( "/tracks/156709825", function(sound) { var is_playing = true; sound.play(); document.getElementById("play_1").onclick = function(){ if(is_pl
function play_pause() {
SC.stream( "/tracks/156709825", function(sound) {
var is_playing = true;
sound.play();
document.getElementById("play_1").onclick = function(){
if(is_playing === false){
sound.resume();
is_playing = true;
} else if(is_playing === true){
sound.pause();
is_playing = false;
}
};
});
}
play_pause();
<button onclick="play_pause();" id="play_1">Play</button>
这一次什么都没用。。它没有被调用,所以我决定使用第三个参数
function startStream() {
console.log('starting stream');
SC.stream("/tracks/156709825",
{autoPlay: false},
function (sound) {
console.log('stream ready');
var is_playing = true;
sound.play();
function togglePause() {
console.log('pause toggled');
if (is_playing) {
sound.pause();
is_playing = false;
} else {
sound.resume();
is_playing = true;
}
console.log('is_playing now', is_playing);
}
var play_button = document.getElementById("play_1");
play_button.addEventListener("click", togglePause, false);
}
);
}
startStream();
这播放,但仍然自动启动,如果有人有任何线索,我将不胜感激
我有几把小提琴。。但是我不知道如何隐藏我的客户id。。所以我觉得把它们贴在这里不舒服我发现了一个解决方法,但我确定这不是正确的处理方法。。我从来没能得到自动播放:错误的工作选项。。所以我就让它响起。播放,然后立即响起。暂停。。然后将“正在播放”状态更改为“开始时为false”
function startStream() {
console.log('starting stream');
SC.stream("/tracks/156709825", {
autoPlay: false },
function (sound) {
console.log('stream ready');
var is_playing = false;
sound.play();
sound.pause();
function togglePause() {
console.log('pause toggled');
if (is_playing) {
sound.pause();
is_playing = false;
} else {
sound.resume();
is_playing = true;
}
console.log('is_playing now', is_playing);
}
var play_button = document.getElementById("play_1");
play_button.addEventListener("click", togglePause, false);
});
}
startStream();
如果你知道一些更干净更好的东西,我喜欢看
function startStream() {
console.log('starting stream');
SC.stream("/tracks/156709825", {
autoPlay: false },
function (sound) {
console.log('stream ready');
var is_playing = false;
sound.play();
sound.pause();
function togglePause() {
console.log('pause toggled');
if (is_playing) {
sound.pause();
is_playing = false;
} else {
sound.resume();
is_playing = true;
}
console.log('is_playing now', is_playing);
}
var play_button = document.getElementById("play_1");
play_button.addEventListener("click", togglePause, false);
});
}
startStream();