2015-11-27 120 views
0

我已經的SoundCloud嵌在我的崗位作爲播放的SoundCloud,沒有API

<iframe class="soundcloud_iframe" width="100%" height="166" scrolling="no" frameborder="no" src="'.esc_url('https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F'.$custom['soundcloud'][0].'').'"></iframe> 

哪裏$custom['soundcloud'][0]的是,我可以把我的帖子後自定義類型,它是歌曲的ID上的SoundCloud。

我還覆蓋了我的soundcloud iframe,它加載了默認播放器,並帶有'cover_over_soundcloud'絕對定位的div,它上面有一個「播放按鈕」。

所以當你點擊它時,iframe應該開始播放。

var $soundcloud_iframe = $('.soundcloud_iframe'); 
 

 
    if ($('.cover_over_soundcloud').length) { 
 
     $('.play_button').on('click', function() { 
 
     $(this).parent().fadeOut(); 
 
     $soundcloud_iframe.play(); 
 
     }); 
 
    }
.cover_over_soundcloud { 
 
    position: absolute; 
 
    min-height: 200px; 
 
    width: 100%; 
 
    background: #fdfdfd; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
} 
 
.cover_over_soundcloud .play_button { 
 
    position: absolute; 
 
    border: 3px solid #272727; 
 
    border-radius: 50%; 
 
    width: 50px; 
 
    height: 50px; 
 
    top: 75px; 
 
    left: 50%; 
 
    margin-left: -25px; 
 
    text-align: center; 
 
    line-height: 50px; 
 
    cursor: pointer; 
 
} 
 
.cover_over_soundcloud .play_button:after { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 30%; 
 
    left: 43%; 
 
    border-left: 10px solid #272727; 
 
    border-top: 10px solid transparent; 
 
    border-bottom: 10px solid transparent; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="cover_over_soundcloud"> 
 
    <div class="play_button"></div> 
 
</div> 
 
<iframe class="soundcloud_iframe" width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F192479201"></iframe>

現在,因爲我使用的SoundCloud API是,我不能使用官方soundcloud widget methods,尤其是.play()這是我所需要的。

是否有解決方法?

點擊一個播放按鈕只需要再次點擊soundcloud播放按鈕是有點愚蠢。

我隱藏它,因爲它在我的網站上看起來不太好,所以這是一種解決方法。

+0

這個問題類似於此[柱](http://stackoverflow.com/questions/14913649/how-to-change-background-color-of-external-page-loaded-into-iframe) 。你喜歡做什麼是安全限制。如果源是外部頁面,則無法訪問iframe源。 – Chris

+0

所以沒有辦法做到這一點,除非我使用API​​? :\ –

+0

點擊你的播放按鈕後,該腳本可以更改iframe的SRC,因爲有自動播放選項[請參閱此處](http://shareandembed.help.soundcloud.com/customer/portal/articles/2167173-visual-embedded -player-)。但閱讀wohle文章:這不適用於移動設備 – Chris

回答

0

看看下面。

而不是使用SoundClouds默認播放器將您的播放器扔到另一個具有一些isset值的自定義頁面來拉動MP3,使其看起來像這樣。

<iframe class="soundcloud_iframe" width="100%" height="166" scrolling="no" frameborder="no" src="http://www.example.com/song.php?mp3=https://api.soundcloud.com/tracks/'.$id.'/stream?client_id='.$MyClientID.'"></iframe> 

你想要做什麼是不可能使用他們的默認播放器,而不是使用API​​,希望這有助於。

<script type="text/javascript"> 
$(document).ready(function() { 
$("#player4").flatie({ 
    media: { 
    mp3: "<?php echo isset($_GET['mp3']) ? $_GET['mp3'] : ''; ?>" 
}, 
    swfPath: "" 
}); 
}); 

</script> 
+1

'flatie'是一個不同的球員? –

+0

@dingo_D對不起,我是移動設備,那是我的一個玩家 - 只需將其改爲適合您的請求,使用上面顯示的方法,您可以使用與您現在使用的方法相同的方法,而不是將SoundCloud iframe拉到音頻mp3中你可以創建你自己的球員。我之所以提到這個,是因爲你說你不喜歡當前的網站在你的網站上的樣子。 –

+0

是的,這是一個選項,但不是我尋找的解決方案。感謝你的努力。 –