递归查找所有音频文件并随机播放
Find all audio files recursively and play them at random
有什么方法可以找到所有的音频文件并随机播放。
我对任何有用的东西都持开放态度。我尝试了很多我在网上找到的不同方法,但它们都用了很多年了,都没有用。
我的服务器有 2000 多首歌曲,而且还会增加。
目录示例:
/var/html/Music/
song1.mp3
song2.mp3
/var/html/Music/Artist1/
Song1.mp3
/var/html/Music/Artist1/Album 1/
Song that has spaces and - (Parenthesis).mp3
回答我是如何得到我需要的东西的:
首先,我 运行 在我的 linux 服务器上执行命令以查找我的音乐目录中的所有文件 (-f),并为每个文件创建一个带有 link 的输出“/Directory/For/Music/song.mp3
find /Directory/For/Music/ -type f > /Any/Directory/You/Want/songs.index
然后:
<?php
/**Gets the list of files and returns a random line of the file**/
$f_contents = file("/var/www/html/scripts/songs.index");
$line = $f_contents[array_rand($f_contents)];
$data = $line;
/** print the contents of the names array */
echo($data);
?>
有什么方法可以找到所有的音频文件并随机播放。
我对任何有用的东西都持开放态度。我尝试了很多我在网上找到的不同方法,但它们都用了很多年了,都没有用。
我的服务器有 2000 多首歌曲,而且还会增加。
目录示例:
/var/html/Music/
song1.mp3
song2.mp3
/var/html/Music/Artist1/
Song1.mp3
/var/html/Music/Artist1/Album 1/
Song that has spaces and - (Parenthesis).mp3
回答我是如何得到我需要的东西的:
首先,我 运行 在我的 linux 服务器上执行命令以查找我的音乐目录中的所有文件 (-f),并为每个文件创建一个带有 link 的输出“/Directory/For/Music/song.mp3
find /Directory/For/Music/ -type f > /Any/Directory/You/Want/songs.index
然后:
<?php
/**Gets the list of files and returns a random line of the file**/
$f_contents = file("/var/www/html/scripts/songs.index");
$line = $f_contents[array_rand($f_contents)];
$data = $line;
/** print the contents of the names array */
echo($data);
?>