下面类似html5 mp3player代码的动态地址和未知文件名


dynamic address and unknown file name for html5 mp3player like code below

正如你在下面看到的,我的代码完全可以从用户那里读取上传的mp3文件,然后将其传递给flash播放器播放。

if($uplfile !="")
    $url = $my_base_url.$my_website_base."/modules/upload/attachments/".$uplfile;
else    
    $url = $this->get_template_vars('enc_url');
$info = pathinfo($url);
if ($info["extension"] == "mp3") 
{
{/php} 
<center>  
  <object type="application/x-shockwave-flash" data="{$my_base_url}{$my_website_base}/templates/{$the_template}/img/player_mp3_maxi.swf" width="200" height="20">
    <param name="movie" value="{$my_base_url}{$my_website_base}/templates/{$the_template}/img/player_mp3_maxi.swf" />
    <param name="bgcolor" value="#ffffff" />
{php}   
echo '    <param name="FlashVars" value="'.urldecode($url).'" />
    <param name="FlashVars" value="mp3='.$url.'&amp;showstop=1&amp;showinfo=1&amp;showvolume=1" />
</object>  
</center>';

然而,我想使用html5播放器代替。我会说这样的话。

<audio controls>
  <source src=" **? Don't Know What to put ?** " type="audio/ogg">
  <source src=" **? Don't Know What to put ?** " type="audio/mpeg">
        </audio>

为了读取文件,我尝试了所有可能的源代码,但仍然无法做到。请注意,我没有文件名,并且未知,将由用户上传。提前谢谢。这是我第一次使用这个网站,所以如果我没有完全遵守提问规则,请忽略。

编辑

我使用了以下代码我保留了HTML5和javascript,看看哪一个能用。我想去掉swf闪存,因为它与移动设备兼容,所以可以正常工作。

{php}
global $db,$my_base_url,$my_pligg_base;
$lid = $this->get_template_vars('link_id');
$uplfile = $db->get_var("select file_name from ".table_prefix."files where file_link_id='".$lid."'  and file_size='orig'");

if($uplfile !="")
    $url = $my_base_url.$my_pligg_base."/modules/upload/attachments/".$uplfile;
else    
    $url = $this->get_template_vars('enc_url');
$info = pathinfo($url);
if ($info["extension"] == "mp3") 
{
{/php} 
<audio controls>
  <source src=" $url " type="audio/ogg">
  <source src=" $url" type="audio/mpeg">
        </audio>
<script type="text/javascript">
function music(track){
   $('#audioPlayer').attr('src', track);
   $('#audioPlayer').attr('autoplay', 'autoplay');
   $.get();
   }
function pauseAudio(){
   $('#audioPlayer').get(0).pause();
   }
   </script>
<img alt="" onclick="music('http://www.raphmond.com/modules/upload/attachments/'); return false;" src="http://www.raphmond.com/templates/coolstrap/img/play.png"> 
<img alt="" onclick="pauseAudio(); return false;" src="http://www.raphmond.com/templates/coolstrap/img/pause.png"> 
<audio id="audioPlayer" src=""></audio>

<center>  
  <object type="application/x-shockwave-flash" data="{$my_base_url}{$my_pligg_base}/templates/{$the_template}/img/player_mp3_maxi.swf" width="200" height="20">
    <param name="movie" value="{$my_base_url}{$my_pligg_base}/templates/{$the_template}/img/player_mp3_maxi.swf" />
    <param name="bgcolor" value="#ffffff" />
{php}   
echo '    <param name="FlashVars" value="'.urldecode($url).'" />
    <param name="FlashVars" value="mp3='.$url.'&amp;showstop=1&amp;showinfo=1&amp;showvolume=1" />
</object>  
</center>';

应该工作。

<audio controls src="where-you-keep-your-uploaded-file"></audio>

如果相对路径不起作用,请尝试完整路径(例如。http://www.yourwebsite.com/music/user-file.mp3)

我曾经不得不写这样的剧本,但我使用定制的按钮来播放/暂停。它看起来像这样,工作得很完美。

HTML

<img alt="" onclick="music('http://www.my-website.org/media/myfile.mp3'); return false;" src="gfx/play.png"> 
<img alt="" onclick="pauseAudio(); return false;" src="gfx/pause.png"> 
<audio id="audioPlayer" src=""></audio>

JavaScript

function music(track){
   $('#audioPlayer').attr('src', track);
   $('#audioPlayer').attr('autoplay', 'autoplay');
   $.get();
   }
function pauseAudio(){
   $('#audioPlayer').get(0).pause();
   }

假设您的路径实际上是有效的,那么应该不会有任何问题。