Tune WinAmpTuneController::getTune(const HWND &hWnd) { Tune tune = Tune(); int position = (int)SendMessage(hWnd, WM_WA_IPC, 0, IPC_GETLISTPOS); if (position != -1) { if (hWnd && SendMessage(hWnd,WM_WA_IPC,0,IPC_ISPLAYING) == 1) { QPair<bool, QString> trackpair(getTrackTitle(hWnd)); if (!trackpair.first) { // getTrackTitle wants us to retry in a few ms... int interval = AntiscrollInterval; if (++antiscrollCounter_ > 10) { antiscrollCounter_ = 0; interval = NormInterval; } setInterval(interval); return Tune(); } antiscrollCounter_ = 0; tune.setName(trackpair.second); tune.setURL(trackpair.second); tune.setTrack(QString::number(position + 1)); tune.setTime(SendMessage(hWnd, WM_WA_IPC, 1, IPC_GETOUTPUTTIME)); } } return tune; }
Tune AimpTuneController::getTune() const { HANDLE aFile=OpenFileMapping(FILE_MAP_READ, TRUE, AIMP_REMOTE_CLASS); PAIMPRemoteFileInfo aInfo = (PAIMPRemoteFileInfo)MapViewOfFile(aFile, FILE_MAP_READ, 0, 0, AIMPRemoteAccessMapFileSize); if (aInfo != NULL) { wchar_t *str = (wchar_t *)((char*)aInfo + sizeof(*aInfo)); QString album = QString::fromWCharArray(str, aInfo->AlbumLength); str += aInfo->AlbumLength; QString artist = QString::fromWCharArray(str, aInfo->ArtistLength); str += aInfo->ArtistLength + aInfo->DateLength; QString url = QString::fromWCharArray(str, aInfo->FileNameLength); str += aInfo->FileNameLength + aInfo->GenreLength; QString title = QString::fromWCharArray(str, aInfo->TitleLength); unsigned long trackNumber = aInfo->TrackNumber; unsigned long time = aInfo->Duration; Tune tune = Tune(); if (!url.isEmpty()) { if (!title.isEmpty()) { tune.setName(title); } else { int index = url.replace("/", "\\").lastIndexOf("\\"); if (index > 0) { QString filename = url.right(url.length()-index-1); index = filename.lastIndexOf("."); title = (index > 0) ? filename.left(index) : filename; } else { title = url; } tune.setName(title); } if (trackNumber > 0) { tune.setTrack(QString::number(trackNumber)); } if (time > 0) { tune.setTime((uint)time); } if (!artist.isEmpty()) { tune.setArtist(artist); } if (!album.isEmpty()) { tune.setAlbum(album); } tune.setURL(url); } return tune; } UnmapViewOfFile(aInfo); CloseHandle(aFile); return Tune(); }
Tune FileTuneController::currentTune() { Tune tune; QFile file(songFile_); if (file.open(QIODevice::ReadOnly)) { QTextStream stream( &file ); stream.setCodec("UTF-8"); stream.setAutoDetectUnicode(true); tune.setName(stream.readLine()); tune.setArtist(stream.readLine()); tune.setAlbum(stream.readLine()); tune.setTrack(stream.readLine()); tune.setTime(stream.readLine().toUInt()); } return tune; }
void ITunesController::iTunesCallback(CFNotificationCenterRef,void* observer,CFStringRef,const void*, CFDictionaryRef info) { Tune tune; ITunesController* controller = (ITunesController*) observer; CFStringRef cf_state = (CFStringRef) CFDictionaryGetValue(info, CFSTR("Player State")); if (CFStringCompare(cf_state,CFSTR("Paused"),0) == kCFCompareEqualTo) { //qDebug() << "itunesplayer.cpp: Paused"; emit controller->stopped(); } else if (CFStringCompare(cf_state,CFSTR("Stopped"),0) == kCFCompareEqualTo) { //qDebug() << "itunesplayer.cpp: Stopped"; emit controller->stopped(); } else if (CFStringCompare(cf_state,CFSTR("Playing"),0) == kCFCompareEqualTo) { //qDebug() << "itunesplayer.cpp: Playing"; tune.setArtist(CFStringToQString((CFStringRef) CFDictionaryGetValue(info, CFSTR("Artist")))); tune.setName(CFStringToQString((CFStringRef) CFDictionaryGetValue(info, CFSTR("Name")))); tune.setAlbum(CFStringToQString((CFStringRef) CFDictionaryGetValue(info, CFSTR("Album")))); CFNumberRef cf_track = (CFNumberRef) CFDictionaryGetValue(info, CFSTR("Track Number")); if (cf_track) { int tracknr; if (!CFNumberGetValue(cf_track,kCFNumberIntType,&tracknr)) { qWarning("itunesplayer.cpp: Number value conversion failed."); } tune.setTrack(QString::number(tracknr)); } CFNumberRef cf_time = (CFNumberRef) CFDictionaryGetValue(info, CFSTR("Total Time")); int time = 0; if (cf_time && !CFNumberGetValue(cf_time,kCFNumberIntType,&time)) { qWarning("itunesplayer.cpp: Number value conversion failed."); } tune.setTime((unsigned int) (time / 1000)); controller->currentTune_ = tune; emit controller->playing(tune); } else { qWarning("itunesplayer.cpp: Unknown state."); } }