【问题标题】:<cfmediaplayer> how to automatically play next track<cfmediaplayer> 如何自动播放下一首曲目
【发布时间】:2013-04-04 21:48:37
【问题描述】:

我一直致力于为我的网站创建一个弹出式播放器,用户可以在其中播放其他用户上传到该网站的音乐播放列表。但是目前我不得不手动单击每个曲目来播放它,我想知道是否有人设法创建了一个&lt;cfmediaplayer&gt;,它会自动播放播放列表中的下一首歌曲。它知道当前播放哪首歌的方式是在一个 url 变量中定义的,该变量发送用户点击的曲目名称,然后调用数据库查看是否可以找到匹配项,然后我使用源输出位置我存储的曲目。生病发布代码以更清楚地了解我在做什么:

<cfquery datasource="#mydatabase#" name="getsongs">
    Select *
    From artists, songs
    Where artist_id = song_artistid
</cfquery>

<cfif IsDefined("URL.song")>
    <cfquery datasource="#mydatabase#" name="playsong">
        Select *
        From songs
        Where artist_id = song_artistid
        And song_name = '#URL.song#'
    </cfquery>
</cfif>

<div style="margin: 0 auto; width: 800px;>
    <div style="width: 300px; float: left; overflow: scroll;">
        <cfoutput query="getartists">
            <a href="popup_player.cfm?song=#song_name#>#artist_name# - #song_name#</a>
        </cfoutput>
    </div>

    <cfif IsDefined("URL.song")>
        <div style="width: 500px; float: right;">
            <cfoutput>
                <cfmediaplayer name="song" source="artists/songs/#playsong.song_location#" autoplay="yes" height="500" width="500"></cfmediaplayer>
            </cfoutput>
        </div>
    </cfif>
</div>

如您所见,我有一个滚动 div,其中列出了用户播放列表中的所有歌曲。通过单击歌曲,它会更新在媒体播放器中播放的曲目。我想知道是否有任何方法可以在歌曲完成后自动单击下一个链接,并且也许有一种方法,如果一个变量已设置为在到达最后一首曲目时重复播放列表,它会再次回到第一个。

【问题讨论】:

    标签: javascript jquery coldfusion


    【解决方案1】:

    请参阅 CFMEDIAPLAYER (http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSE66DB0CD-E16D-49e7-AAEE-F51F9580554E.html) 的参考指南。它支持在轨道结束时运行 JavaScript。您可以使用它来自动调用下一首曲目。

    【讨论】:

    • 干杯!唯一的问题是,我如何编写 JavaScript 来检查播放列表中的下一首曲目是什么?我将这样做,所以当用户创建播放列表时,它会为他们创建一个唯一的 XML,所以想知道我是否可以为用户设置的曲目创建一个播放列表编号,以便在解析和选择下一个曲目方面更容易。
    • 如果您知道轨道服务器端,您可以将它们输出为您的代码可以使用的 JS 变量。请参阅 toScript()。这是另一篇可能有帮助的博文:raymondcamden.com/index.cfm/2012/8/27/…
    • 是的,我可以在服务器端读取它们,而不必在客户端物理声明它们,使用 toScript() 函数我应该能够轻松地传递当前行的值,允许它为我提供正确的链接。
    【解决方案2】:

    您可以在歌曲结束时运行 javascript。 添加到您当前的代码:

     <cfmediaplayer onComplete=" YOUR_PLAY_NEXT_FUNCTION"  name="song"
     source="artists/songs/#playsong.song_location#" autoplay="yes"
     height="500" width="500"></cfmediaplayer>
    

    从 cmets 添加

    我还没有尝试过,但这对你有用吗?

    var i = 0; // This should be the current song_no 
    $("#button").on('click', function(){ 
        // Adds +1 to the current song number
        i++  
        // Create a variable using the standard url + the added song-number
        var curr_song = "artists/songs/#playsong.song_location#"+i;  
        // Changes the attribute to the new song-url 
        $('cfmediaplayer').attr("name",curr_song); 
    });
    

    【讨论】:

    • 我唯一的问题是javascript;我怎样才能让它知道接下来要播放哪个曲目?我编辑过的一件事是我在 URL 中添加了一个 playlistNo 变量,其中值是当前行,所以它知道在查询中跳转到哪里。我所需要的是,当它结束时它知道去链接&lt;a href="popup-player.cfm?song=#song_name#&amp;playlistNo=#currentrow# + 1&gt;这怎么能在javascript中完成?
    • @Leeb 我没试过,但这对你有用吗? var i = 0; // This should be the current song_no $("#button").on('click', function(){ i++ // Adds +1 to the current song number var curr_song = "artists/songs/#playsong.song_location#"+i; // Create a variable using the standard url + the added song-number $('cfmediaplayer').attr("name",curr_song); // Changes the attribute to the new song-url });
    • 如果 JavaScript 显示播放列表所在的当前行,这将是一个好的解决方案。不幸的是,它没有,每首歌曲根据它在查询中的位置都有自己的行,这就是我想通过编辑当前行并自动移动到列表中的下一行来控制曲目导航的方式。
    【解决方案3】:

    好的,我以前从未使用过 cfmediaplayer,但这个伪代码应该可以让你到达你需要的地方。

    这些是我使用的资源。

    1. Dynamically starting and stopping a video using JavaScript and the CFMEDIAPLAYER tag in ColdFusion
    2. ColdFusion.Mediaplayer.setSource
    3. cfmediaplayer

    <cfquery ...>
    Select
       songUrl
    from
       songs
    </cfquery>
    <!--- build your coldFusion array of song URLs --->
    <cfset urlList = valueList(query.songURL)>
    <cfset urlArray = listToArray(urlList)>
    
    <script>
        <cfoutput>
        #toScript(urlArray)#
        var songIndex = #query.currentRow-1#; <!--- or url.currentRow, whatever you're using --->
        </cfoutput>
        startNext(){
            songIndex++;
            if(songIndex <= urlArray.length){                
                ColdFusion.Mediaplayer.setSource('mediaPlayerName', urlArray[songIndex]);
                ColdFusion.Mediaplayer.startPlay('mediaPlayerName');
            }
        }
    </script>
    

    【讨论】:

      猜你喜欢
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多