drogon982007 2013-02-19 00:06
浏览 41
已采纳

设置动态音频播放列表

I'm using an HTML5 audio player (Speakker). I've created a function to dynamically create a playlist, but I'm not sure how to implement the playlist once I've created it. This seems like the sort of thing that someone with more experience might just take for granted. I hope that's the case.

Create the playlist. Check.

    <?php $playlist= "{\"playlist\": [";?>
    <?php foreach ($items as $item){
        $titlemetadata= metadata($item, array('Dublin Core', 'Title'));
            foreach($item->Files as $file) {
                // print_r($file);
                $sourcemetadata= metadata($file, 'uri');
                $imagemetadata= metadata($file, 'thumbnail_uri');
                if (strpos($file["filename"], 'mp3') !== false) {
                    $playlist .=
                    "\"0\": {\"src\":\"$sourcemetadata\", \"type\":\"audio/mp3\"}, 
                    \"config\": 
                    {\"title\": \"$titlemetadata\",
                    \"poster\": \"$imagemetadata\"}";
                }
            }       
    }?>
    <?php $playlist .= "]}";?>
    <?php echo $playlist;?>

Implement the playlist? Nope.

<audio class="projekktor speakker dark"> <source src= ??THE PLAYLIST?? type="application/json"/> </audio>

  • 写回答

1条回答 默认 最新

  • duanbo7517 2013-02-20 23:10
    关注

    I got it worked out. Here's a solution:

    <?php $collections=get_records("collection", array("public"=>"true","featured"=>"true"));
      $current_collection=end($collections);
      $items=get_records("item", array("collection"=>$current_collection));
    
      $playlist= "[";
      foreach ($items as $item){
        $titlemetadata= metadata($item, array("Dublin Core", "Title"));
            foreach($item->Files as $file) {
                $sourcemetadata= metadata($file, "uri");
                $imagemetadata= metadata($file, "thumbnail_uri");
                if (strpos($file["filename"], "mp3") !== false) {
                    $playlist .=
                    "{\"0\": {\"src\":\"$sourcemetadata\", \"type\":\"audio/mp3\"}, 
                    \"config\": 
                    {\"title\": \"$titlemetadata\",
                    \"poster\": \"$imagemetadata\"}},";
                }
            }       
       }
       $playlist .= "]";?>
    <?php 
        $string = '$(document).ready(function() {projekktor(".projekktor").setFile(' . $playlist . ');});';
    queue_js_string($string);?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100