javascript - html5 mp3player 的动态地址和未知文件名,如下面的代码

标签 javascript php html media-player flash

正如您在下面看到的,我的代码完全可以读取用户上传的 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 flash。

{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();
   }

假设您的路径实际上有效,应该没有问题。

关于javascript - html5 mp3player 的动态地址和未知文件名,如下面的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25815957/

相关文章:

javascript - 在 React 和 HTML 中渲染多个图像

javascript - 空白 : pre-wrap with word-break: break-all recently became very slow in Chrome

html - CSS 流体图像问题

javascript - 如何正确使用Javascript "export"和 "import"函数?

php - 在查询的 while 循环中创建关联数组

php - ffmpeg - 来自 rtsp 的实时视频,带有 mp4 碎片

javascript - JQuery 与 php 显示 div 元素

javascript - 具有数组属性的 angular.extend/merge 对象

javascript - 如何配置 jshint 不给我错误 "Bad line breaking before"?

javascript - 如何查找具有特定数据属性值的元素