Read Information Song (MetaData or TAG song) using file path on BB10 cascades


/*
*reference from :
*http://supportforums.blackberry.com/t5/Cascades-Development/Reading-mp3-tags/td-p/2126579
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
char tag[3];
char title[30];
char artist[30];
char album[30];
char year[4];
char comment[30];
unsigned char genre;
} mp3Tag;
QString ClassName::ReadInfoSong(const QString MP3_FILENAME) {
FILE *fp = fopen(MP3_FILENAME, "rb");
if (!fp) {
perror("File open failed");
return "1";
}
mp3Tag tag;
// Seek to 128 bytes before the end of the file
if (fseek(fp, -1 * sizeof(mp3Tag), SEEK_END) == -1) {
perror("fseek failed");
return "2";
}
// Read the tag
if (fread(&tag, sizeof(mp3Tag), 1, fp) != 1) {
fprintf(stderr, "Failed reading tag\n");
return "3";
}
// Make sure we've got what we expect.
if (memcmp(tag.tag, "TAG", 3) == 0) {
// Found the tag where we expected
printf("Title: %.30s\n", tag.title);
printf("Artist: %.30s\n", tag.artist);
printf("Album: %.30s\n", tag.album);
printf("Year: %.4s\n", tag.year);
if (tag.comment[28] == '\0') {
printf("Comment: %.28s\n", tag.comment);
printf("Track: %d\n", tag.comment[29]);
} else {
printf("Comment: %.30s\n", tag.comment);
}
printf("Genre: %d\n", tag.genre);
} else {
fprintf(stderr, "Failed to find TAG\n");
return "4";
}
return tag.title+"-"+tag.artist+"-"+tag.album+"-"+tag.year;
}
/*
* Note MP3_FILENAME is a file path from song.
*/

Create playlist using QMediaPlayer n QMediaPlaylist on QT


/*
Reffrence :
http://harmattan-dev.nokia.com/docs/library/html/qtmobility/qmediaplaylist.html
http://harmattan-dev.nokia.com/docs/library/html/qtmobility/qmediaplayer.html
*/
/*
on your file .pro
Please add this path declaration QMediaPlayer lib
CONFIG += mobility
MOBILITY = multimedia
QT += multimedia multimediakit
LIBS += -lbbmultimedia
*/
/*
on your file bar-description.xml
Please check permission "access_shared" to access file from your device or your path application
*/
#include <QMediaPlaylist>
#include <QMediaPlayer>
void MyPlayer::playSongs(){
QMediaPlayer player = new QMediaPlayer(this);
QMediaPlaylist playlist = new QMediaPlaylist(this);
playlist.addMedia(QUrl(YOUR_SONG_PATH+"song1.mp3"));
playlist.addMedia(QUrl(YOUR_SONG_PATH+"song2.mp3"));
playlist.addMedia(QUrl(YOUR_SONG_PATH+"song3.mp3"));
playlist.addMedia(QUrl(YOUR_SONG_PATH+"song4.mp3"));
playlist.addMedia(QUrl(YOUR_SONG_PATH+"song5.mp3"));
//replace YOUR_SONG_PATH to your really path songs
playlist.setCurrentPosition(0);
player.play();
}

view raw

MyPlayer.cpp

hosted with ❤ by GitHub

Read File mp3 using QT


#include <QDir>
#include <QDirIterator>
void ReadFile::loadFile(const QString &path){
QDirIterator dirIterator(path,QDir::Files|QDir::NoSymlinks,QDirIterator::SubDirectories);
while(dirIterator.hasNext()){
dirIterator.hasNext();
if(dirIterator.fileInfo().completeSuffix()=="mp3"){
qDebug()<<"FILE NAME : "<<dirIterator.fileName();
}
}
}

view raw

ReadFile.cpp

hosted with ❤ by GitHub