下面类似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.'&showstop=1&showinfo=1&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.'&showstop=1&showinfo=1&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();
}
假设您的路径实际上是有效的,那么应该不会有任何问题。
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 动态分配GA增强型电子商务跟踪器
- onkeyup无法动态创建多个文本区域
- 使用javascript将动态表从一个html页面打印到另一个html页
- 动态代码中存在系统应用程序地址错误
- 谷歌地图API v3:如何以2个动态地址为中心
- 将回复电子邮件地址更改为队列's在动态crm 2011中的电子邮件地址
- 使用表单动态更改地址栏中的URL第2部分
- 使用表单动态更改地址栏中的 URL
- 在动态超链接中隐藏动态电子邮件地址
- 下面类似html5 mp3player代码的动态地址和未知文件名
- 通过动态字段中的动态复选框复制地址
- 动态单击复选框并在列表中添加电子邮件地址,并使用javascript删除重复的电子邮件地址
- 动态jquery地址使用搜索按钮
- 根据服务器的响应动态更改href地址
- 如何动态生成谷歌自动完成地址api
- 使用 JS 动态获取 Web 服务器的地址
- 动态生成的输入的地址ID,通过AJAX发送值
- 当用户输入邮政编码时,如何动态地在另一个文本框中填充地址?