dongzun9958 2011-07-15 06:40
浏览 80
已采纳

在php中为jplayer生成播放列表

i am actually working on this mentioned title. player show the list, its generating perfectly. but i am no where to make it actually play that file. i must be wrong some where. i need advise fox. (ahh if i can attach the files.)

my class

    class DecodDir 
        {
            function getFiles($directory)
            {
                $all_files  = array();
                $handler    = opendir($directory);
                while($files=readdir($handler))
                {
                    if($files!="." && $files!="..")
                    {
                        $all_files[]= $files;
                    }
                }
                closedir($handler);
                return $all_files;
            }
        }

################# file where i am using this class *###############



 <?php

 include("decoddir.php");

 $obj       = new DecodDir();
 $results   = $obj->getFiles("mp3");
 $total     = count($results);
 $string        = "";
 for($i=0; $i<$total; $i++){

    $string .="
        {
        name:'$results[$i]',
        mp3:'mp3/$results[$i]',
        ogg:'$results[$i]'
        },
        ";
 }

    ?>
// its at the top of that html file (ofcorse with the php ext)

and below, this is where it is generating the playlist

var audioPlaylist = new Playlist("2", [
<?php echo $string; ?>
],

http://www.jplayer.org/latest/demo-02/ (the link from where i get jplayer) you can see the audio player with playlist. (actually i don't know hot format the code in here stackoverflow) thanks Rafay

  • 写回答

2条回答 默认 最新

  • duangu3620 2011-07-15 08:51
    关注

    I have taken the liberty of re-factoring the code a bit for you. I don't know exactly what you are trying to do, but it will help to have the beginnings of a better class on your side.

    <?php
    
    class DecodDir
    {
    
        private
            $directory,
            $files;
    
        public function __construct( $directory = null )
        {
            if ( ! is_null($directory) )
            {
                $this->setDirectory( $directory );
            }
        }
    
        public function setDirectory( $directory )
        {
            $this->directory = $directory;
            $this->files = null;
    
            // TODO put some validation in here;
    
            return $this;
        }
    
        public function getDirectory()
        {
            if ( is_null($this->directory) )
            {
                $this->directory = './';
            }
            return $this->directory;
        }
    
        private function getFiles()
        {
            if ( is_null($this->files) )
            {
                $this->files = array();
                $handler    = opendir( $this->getDirectory() );
                while($files=readdir($handler))
                {
                    if($files!="." && $files!="..")
                    {
                        $this->files[]= $files;
                    }
                }
                closedir($handler);
            }
    
            return $this->files;
        }
    
        public function getJson()
        {
            $list = array();
    
            foreach ( $this->getFiles() as $filename )
            {
                $item = new stdClass();
    
                $item->name = $filename;
                $item->mp3 = "mp3/{$filename}";
                $item->ogg = $filename;
    
                $list[] = $item;
            }
    
            $json = json_encode( $list );
    
            return $json;
    
        }
    
        public function countFiles()
        {
            return sizeof( $this->getFiles() );
        }
    
    }
    
    
    $obj = new DecodDir( 'mp3' );
    echo $obj->getJson();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器