HTML5 audio element with dynamic source

后端 未结 4 1822
無奈伤痛
無奈伤痛 2020-12-06 07:11

I have a basic audio player:

4条回答
  •  情歌与酒
    2020-12-06 07:20

    Has the random choice necessarily to be done by php ?

    If not, it will perhaps be simpler to tell javascript to select a random ID in a range. Then pass it to your php script as a GET parameter.

    IN the php side, do a mapping of IDs > MP3 files, so that the same ID always correspond to the same MP3. You can use whatever you want: simple associative array, database, etc. In fact the IDs don't even have to be numbers.

    IF you don't want that someone discover your mapping and said, call directly the wscript with ID X to download your MP3, you may change your mapping at each session for example.... the important thing is that a given ID always refer to the same MP3 at least during a reasonable period.

    I whould also say that doing a redirection to the MP3 file from php may cause problems to some browsers. It is perhaps better to send the correct HTTP headers and actually return the file contents directly without redirecting. Quick example :

    
    

    More info about readfile and header functions

提交回复
热议问题