2013-08-27 3 views
0

을 시작하고 싶습니다. 내 웹 사이트에 내 위젯이있는 방식으로 트랙 목록이 의도적으로 표시되지 않으므로 재생/일시 중지 버튼과 제목 만 볼 수 있습니다. 미니멀리스트와 정말 깨끗한 느낌을줍니다.사운드 클라우드의 삽입 위젯, 그것은 임의의 노래에 때마다 나는 위젯에 대한 많은 기능을보고이 페이지에서

하지만 누군가가 사이트를 방문하거나 새로 고침 할 때마다 임의의 노래부터 시작하고 싶습니다. 이것이 가능한가? 글쎄, 난이 사용하는 자바 스크립트와 JS 위젯 API을 관리했습니다

<iframe width="100%" height="65" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F5346417&amp;color=579ce6&amp;auto_play=true&amp;show_artwork=false"></iframe> 
+0

가능한 복제본 [SoundCloud 기본 오디오 위젯을 사용하면 JavaScript에서 임의로 설정할 수 있습니까?] (http://stackoverflow.com/questions/15572253/with-soundcloud-default-audio-widget-can-you-set -it-to-shuffle-from-javascript) –

답변

2

: 여기

내 코드, 단지 표준 삽입합니다. 이 메서드는 .skip() 메서드를 사용하여 제로와 내 재생 목록의 트랙 수 사이의 난수로 설정합니다. 이것은 또한 자동 시작을 호출합니다.

$(document).ready(function(){ 

    //Variable declaration 
    var player = SC.Widget($('iframe.sc-widget')[0]); 
    var randomVal; 

    //player initialisation 
    player.bind(SC.Widget.Events.READY, function() { 

     randomSong(player); 
     player.play(); 
    }); 

    //Set the random song 
    function randomSong(player) { 

     randomVal = Math.random() * 10; 
     for(i = 0; i < randomVal; i++) 
     { 
      player.next(); 
     } 
    } 
}); 

그것은 구글 크롬 브라우저 나를 위해 완벽하게 작동합니다 :

+1

코드 예제가 있습니까? –

1

여기 내 코드입니다.

이 예제를 내 soundcloud player의 주 소스로 사용했습니다.

이 코멘트에서 볼 수있는 것처럼 임의 함수를 추가했습니다.