int Tune::getID3v1(unsigned char offset, char* infobuffer) { // pause track if already playing if (isPlaying()) { pauseMusic(); playState = pause; } // save current position for later unsigned long currentPosition = track.curPosition(); // save the value corresponding to the needed frame for later tagFrame = offset; unsigned char ID3v1[3]; // array to store the 'TAG' identifier of ID3v1 tags unsigned long tagPosition = track.fileSize(); // skip to end of file // skip to tag start tagPosition -= 128; track.seekSet(tagPosition); track.read(ID3v1, 3); // read the first 3 characters available // if they're 'TAG' if (ID3v1[0] == 'T' && ID3v1[1] == 'A' && ID3v1[2] == 'G') { // we found an ID3v1 tag ! // let's go find the frame we're looking for tagPosition = (track.curPosition() + offset); track.seekSet(tagPosition); track.read(infobuffer, 30); // read the tag and store it // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 1; } // if they're not else { // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 0; } }
///事件音乐设置 void AudioManager::onEventOptionMusic(EventCustom* event) { bool isOpen = event->getUserData(); setbIsOpenMusic(isOpen); UserDefault::getInstance()->setBoolForKey("s_music_open", isOpen); DLog::d("music isOpen", isOpen); //设置背景音乐 if(isOpen) { resumeMusic(); } else { pauseMusic(); } setbIsOpenMusic(isOpen); }
int Tune::getID3v2(char* infobuffer) { // pause track if already playing if (isPlaying()) { pauseMusic(); playState = pause; } // save current position for later unsigned long currentPosition = track.curPosition(); unsigned char ID3v2[3]; // pointer to the first 3 characters we read in track.seekSet(0); track.read(ID3v2, 3); // if the first 3 characters are ID3 then we have an ID3v2 tag // we now need to find the length of the whole tag if (ID3v2[0] == 'I' && ID3v2[1] == 'D' && ID3v2[2] == '3') { // Read the version of the tag track.read(pb, 1); int tagVersion = pb[0]; // skip 2 bytes we don't need and read the last 4 bytes of the header // that contain the tag's length track.read(pb, 2); track.read(pb, 4); // to combine these 4 bytes together into a single value, we have to // shift one other to get it into its correct position // a quirk of the spec is that the MSb of each byte is set to 0 length = (((unsigned long) pb[0] << (7*3)) + ((unsigned long) pb[1] << (7*2)) + ((unsigned long) pb[2] << (7)) + pb[3]); if (tagVersion == 2) { findv22(infobuffer); // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 2; } else if (tagVersion == 3) { findv23(infobuffer); // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 3; } else { // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 9; } } else { // go back to where we stopped and enable playback again track.seekSet(currentPosition); if (isPlaying()) { resumeMusic(); playState = playback; } return 0; } }
void GameApp::Resume() { resumeMusic(); }