0

私は実際にこの言及されたタイトルに取り組んでいます。プレーヤーはリストを表示し、完全に生成します。しかし、実際にそのファイルを再生する場所はありません。どこか間違っているに違いない。私はキツネに助言する必要があります。(ああ、ファイルを添付できれば。)

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/ (jplayer の入手先のリンク) プレイリスト付きのオーディオ プレーヤーを見ることができます。(実際には、ここのスタックオーバーフローのコードをホットフォーマットすることは知りません)Rafayに感謝します

4

2 に答える 2

1

私はあなたがやろうとしていることをするために次のサイトでコードを書いたと思います:

http://jplaylister.yaheard.us/

悲しいことに、現在、複数の形式 (mysong1.mp3、mysong1.ogg) で保存されている曲を 1 つのプレイリスト アイテムに折りたたむことはできませんが、それ以外の点では機能が充実しており、多くのカスタマイズ可能なオプションがあります。

お役に立てれば!

于 2012-07-24T12:59:02.107 に答える
1

私はあなたのためにコードを少しリファクタリングする自由を取りました。あなたが何をしようとしているのか正確にはわかりませんが、より良いクラスの始まりをあなたの側に置くことは助けになります.

<?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();
于 2011-07-15T08:51:15.517 に答える