简体   繁体   English

如何用c ++在vlc中播放mp3文件

[英]how to play a mp3 file in vlc with c++

I have to write a c++ code which plays a specified song in VLC. 我必须编写一个在VLC中播放指定歌曲的c ++代码。 I've made some research but i didn't find too much. 我做了一些研究,但我找不到太多。

#include <iostream>
#include <string>
//#include "VLCWrapper.h"
//#include<libvlccore.dll>
//#include<libvlc.dll>
using namespace std;
int main() 
{

    cout << "Welcome to VLC launcher program!" << endl;
    cout << "Please enter a filename: ";
    string filename;
    getline(cin, filename);

    string comm = "vlc \"";
    comm += filename + "\"";
    system(comm.c_str()); //call VLC with the file "filename"
    return 0;
 }

This is what i found, but when i compile appears 'vlc' is not recognized as an internal or external command operable program or batch file. 这是我发现的,但是当我编译时出现'vlc'不被识别为内部或外部命令可操作程序或批处理文件。 I need some help, please. 我需要一些帮助。

Most likely you don't have vlc in path, since when I compile it 很可能你在路径中没有vlc ,因为我编译它时

(had to add this) (不得不加上这个)

#include <cstdlib>

it runs fine (I compiled it with g++ ): 它运行正常(我用g++ ):

$ ./a.out 
Welcome to VLC launcher program!
Please enter a filename: Darkside.mp4
VLC media player 2.1.5 Rincewind (revision 2.1.4-49-gdab6cb5)
[0x1888a58] pulse audio output error: PulseAudio server connection failure: Connection refused
[0x1770028] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
[0x7f8288001248] main vout display error: Failed to resize display

You could try to replace vlc with the full path (eg. /usr/bin/vlc )... 您可以尝试用完整路径替换vlc (例如/usr/bin/vlc )...

In case you are on Windows (poor you), it will be the same, just google the "is not internal or external command" and there will be some tips on how to fix it. 如果你在Windows上(可怜你),它将是相同的,只是谷歌“不是内部或外部命令”,并将有一些如何解决它的提示。

Also, you will need vlc.exe probably, I have never used command line on Windows, so not sure how it works there. 此外,你可能需要vlc.exe ,我从来没有在Windows上使用命令行,所以不知道它是如何在那里工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM