我有一些歌曲,我想通过代码播放我有vlc播放器安装在ubuntu,我想通过vlc播放器播放指定文件夹中的所有歌曲的代码…有没有解决这个问题的办法?任何帮助都会得到重视。
int main (int argc, const char * argv[])
{
char *input=argv[1];
if(input=="play"){
//trigger vlc
}
}该文件夹将已包含所有所需的歌曲。用这些歌曲触发vlc的方法是什么?
发布于 2013-05-16 00:23:56
为你做了一个原型,它不安全,不做错误检查,但它是有效的。
代码:
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
int scan(std::string dir, std::vector<std::string> &files)
{
DIR* dr = opendir(dir.c_str());
struct dirent *drp;
while ((drp = readdir(dr)) != NULL)
{
struct stat s;
stat((dir + "/" + std::string(drp->d_name)).c_str(), &s);
if (s.st_mode & S_IFREG)
{
files.push_back(std::string(drp->d_name));
}
}
closedir(dr);
return 0;
}
int main()
{
std::string dir = ".", cmd = "vlc";
std::vector<std::string> files, vfiles;
scan(dir, files);
for (unsigned int i = 0; i < files.size(); i++)
{
if (files[i].substr(files[i].find(".")) == ".mp3")
{
vfiles.push_back(std::string(files[i]));
}
}
for (unsigned int i = 0; i < vfiles.size(); i++)
{
cmd += " " + dir + "/" + vfiles[i];
}
printf("%s\n", cmd.c_str());
system(cmd.c_str());
return 0;
}输出:
vlc ./test.mp3 ./test2.mp3它的作用是:它列出指定文件夹"."中的所有文件默认情况下,它检查文件实际上是一个文件而不是一个文件夹,然后它会列出所有以".mp3"结尾的文件,然后运行vlc file1.mp3 file2.mp3 file4.mp3。VLC将按顺序播放所有列出的文件。
在将其添加到Path之后,在Windows8上使用(VLC media player 2.0.6 Twoflower)。
https://stackoverflow.com/questions/16568640
复制相似问题