I want to get 3rd part softeware can decode music with no-ascll name such as chinese
-
now, i am useing libzply. but when i open a music named by chinese ,libzplay will open err;
bool LuoMusic::musicDecode(const QString &filename) { // filename.toLocal8Bit() QByteArray ba = filename.toUtf8(); const char * name = ba.data(); qDebug()<<name; ZPlay *player = CreateZPlay(); if(player == 0) return false; int ver = player->GetVersion(); // check if we have version 1.90 and above ( 1.90 if PF (pattent free) version, 2.00 version is full version if(ver < 190) { player->Release(); return false; } // qDebug()<<QString("libZPlay v.%1.%2i\r\n\r\n").arg(ver / 100).arg(ver % 100); if(player->OpenFile(name, sfAutodetect) == 0) { qDebug()<<QString("Error: %1 \nPress key to exit.\r\n").arg(player->GetError()); // getch(); player->Release(); return false; } }
thank for your help
-
Hi,
What exact error your getting ?
-
if(player->OpenFile(name, sfAutodetect) == 0)
{
qDebug()<<QString("Error: %1 \nPress key to exit.\r\n").arg(player->GetError());
// getch();
player->Release();
return false;
}like this:
Error: File open error. \nPress key to exit.\r\n -
What OS are you on ?
-
@chaochao said in I want to get 3rd part softeware can decode music with no-ascll name such as chinese:
now, i am useing libzply. but when i open a music named by chinese ,libzplay will open err;
QByteArray ba = filename.toUtf8();
Are you sure your filename and paths are correct? Are your filenames written in UTF-8?
Call
qDebug() << QDir::current().entryList()
. Is your file in the list? -
Since you are passing the path to an external library you should call QDir::toNativeSperators use the result to pass the path to
player->OpenFile
-
@SGaist I did that ,but i got a same err. I think the problem is not this.Because when i pass the path like this C:\Users\Public\Music\Sample Music\Sleep Away.mp3 ,it will be ok.But when Sleep Away is replaced with chinese ,it will return err.
-
@chaochao said in I want to get 3rd part softeware can decode music with no-ascll name such as chinese:
when i pass the path like this C:\Users\Public\Music\Sample Music\Sleep Away.mp3 ,it will be ok.But when Sleep Away is replaced with chinese ,it will return err.
What encoding is your filename? UTF-8, or EUC-CN, or GB18030, or something else?
-
@chaochao said in I want to get 3rd part softeware can decode music with no-ascll name such as chinese:
GBK2312
If your filename is not encoded in UTF-8, that means
toUtf8()
will give you the wrong path.Try converting your filename to the GB2312, not UTF-8:
QTextCodec* codec = QTextCodec::codecForName("GB2312"); QByteArray ba = codec->fromUnicode(filename); const char* name = ba.data();
-
@chaochao said in I want to get 3rd part softeware can decode music with no-ascll name such as chinese:
@JKSH as your code ,if i qDebug()<<name;
it will output
C:/Users/Public/Music/Sample Music/????.mp3What do you see if you call
qDebug() << ba
?Does zplay recognize this name?
What happens if you use Windows functions to get the filename? http://stackoverflow.com/questions/3176208/files-in-directory-in-c
-
Don't forget you still need to first convert the path to native separators before passing it to your other library.