duandian4501 2014-01-16 23:12
浏览 89
已采纳

随机背景音乐循环PHP

on a particular website I currently have a script that randomises the background music that is played each time the website is accessed. It grabs the file randomly from a sound folder and plays. Everything works great.

PHP

$songs = glob('snd/*.*');

HTML

<embed src="swf/player.swf" id="radioplayer" name="radioplayer" quality="medium" allowScriptAccess="always" width="1" height="1" type="application/x-shockwave-flash" FlashVars="file=<?php echo $song; ?>&volume=10&start=0&duration=0&autostart=true&controlbar=none&dock=false&icons=false&loop=1">

However, I would like to expand this a little more.

It is used as a loading screen for a gameserver which requires custom files to be downloaded to the client. Once the song finishes, it's just silence. I'm wondering: is it possible that when the song is finished a new song is selected randomly, like how it was the first time, and then played? The only thing is, even though I want the selection to be random I do not want it to play the song that was just played.

Hopefully this is possible and thanks in advance.

Note

It uses a flash player to play the songs, as you can see. If this is not a viable method of playing the songs with my request above I'm welcome to alternative methods, provided I can control the volume of the audio that plays.

Edit

To try and kill two birds with one stone, the webpage's background image also changes depending on which map the server is currently using. I do not have images for each map I add as I add more all the time, would it be possible to set the background to a default image instead of it just being blank?

  • 写回答

1条回答 默认 最新

  • doumengyin0491 2014-01-16 23:15
    关注

    Im doing this in javacript, you could just add the song as a string creating the Audio object!
    Example

     var titleTheme = new Audio("PUT_RANDOM_SONG_HERE");
    

    Real World
    The magic and what you are looking for is to add an event listener too the event "ended".

    var titleTheme = new Audio("AUDIO/tmnt.mp3");
    
    //Start up with this
    titleTheme.play();
    
    // Events _________________________________________________ 
    // BIND TITLE THEME ENDED
    titleTheme.addEventListener('ended',endings);
    function endings()
    {
     titleTheme.play();
    }
    

    Things to know, not all browsers play all the fileformats. So you will have to be able to supply audio as per browser.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题