Click here to Skip to main content
15,885,141 members
Articles / Mobile Apps

Pocket PC Personal MP3 Disc Catalogue Search Tool

Rate me:
Please Sign up or sign in to vote.
3.33/5 (3 votes)
21 Sep 2005CPOL2 min read 44.1K   487   24   7
Windows Mobile application to search MP3 music catalogue
Sample Image - PocketCatalogue.gif

Introduction

This application is essentially a search tool for finding what Disc Number the Music Album I want to listen to is on. This application also contains functionality to download its data from the central Database server (via a WebService).

I'm still actively working on this project, so please give me your constructive comments and design suggestions. Right now, this app is very specialized for my needs, but if there is enough interest (and good design direction ideas) I could easily be persuaded to update and morph the project.

Framework note

Special note: Thanks to the following article on CodeProject. It helped me a lot (plus I sampled parts of their code).

Background

I have an extensive collection of MP3s that I sort by Album folder and burn onto CD-R for use in my car stereo. Once I got to 100 discs (Over 900 albums) I realized that I needed a better way of finding the music I wanted to listen to. So I created a MySQL database on my server and a search tool on my Pocket PC.

Snippets

Part of the code used to create the database that is used on the Pocket PC:

C#
// This code is in the frmMain_Load event of the frmMain class
PocketCatalogue.Database myDB;
myDB = new Database(PathToDatabase,DatabaseName);
myDB.CreateDB();

// This code is in the Database class
public void CreateDB() {
    if (!System.IO.File.Exists(_pathToDatabase + _databaseName)) {
        SqlCeEngine engine;
        engine = new SqlCeEngine("Data Source = " + _pathToDatabase + _databaseName);
        engine.CreateDatabase();
        engine = null;
        CreateTables();
    }
}
public void CreateTables(){
    if (conn == null) {GetConnected();conn.Open(); }
    try {
        string SQL = "CREATE TABLE Albums ( " +
            "DiscID int, " +
            "AlbumID int, " +
            "ArtistName nvarchar(254), " +
            "AlbumName nvarchar(254), " +
            "Genre nvarchar(45) )";

        SqlCeCommand createTable = conn.CreateCommand();
        createTable.CommandText = SQL;
        createTable.ExecuteNonQuery();

        SQL = "CREATE TABLE Discs ( " +
            "DiscID int, " +
            "DiscNumber int, " +
            "DiscName nvarchar(45), " +
            "HasLabel int )";

        createTable = conn.CreateCommand();
        createTable.CommandText = SQL;
        createTable.ExecuteNonQuery();

    } catch (System.Data.SqlServerCe.SqlCeException ex) {
        MessageBox.Show(ex.Message, "DB Error");
    }
}
private void GetConnected(){
    conn = new SqlCeConnection("Data Source = " + _pathToDatabase + _databaseName);
}

Part of the code used to check for network connectivity before enabling the WebService calls:

C#
// This code is in the ConnectivityTest class
public bool IsWebAccessible() {
    HttpWebRequest hwrRequest;
    HttpWebResponse hwrResponse;

    string strUrl = @"http://www.microsoft.com/";
    bool bConnected = false;

    try{
        hwrRequest = (HttpWebRequest)WebRequest.Create(strUrl);
        hwrRequest.Timeout = 10;
        hwrResponse = (HttpWebResponse)hwrRequest.GetResponse();

        if(hwrResponse.StatusCode == HttpStatusCode.OK){
            bConnected = true;
        }
    }catch(WebException we){
        bConnected = false;
    }catch(Exception ex){
        bConnected = false;
    }finally{
        hwrRequest = null;
        hwrResponse = null;
    }

    return bConnected;
}

Method used to make the DataGrid pretty and autosized:

C#
// This code is in the Util class
public static void FormatDataGrid(DataGrid dg, DataSet ds) {
    Font f2 = new Font("Tahoma",7, System.Drawing.FontStyle.Regular);
    dg.Font = f2;
    if (ds != null) {
        if (dg.TableStyles.Count > 0)
            dg.TableStyles.Clear();
        float sumWidths = 0.0f;
        foreach (DataTable dt in ds.Tables) {
            DataGridTableStyle DGStyle = new DataGridTableStyle();
            DGStyle.MappingName = dt.TableName;
            DataGridTextBoxColumn textColumn;
            System.Collections.ArrayList cWidths;
            cWidths = new System.Collections.ArrayList();
            Graphics g = dg.CreateGraphics();
            Font f = dg.Font;
            SizeF sf;
            int y = 0;
            foreach (DataColumn dc in dt.Columns) {
                sf = g.MeasureString("W" + dc.Caption, f);
                //cWidths.Add(sf.Width);
                if (y == 0)
                    cWidths.Add(36);
                else
                    cWidths.Add(102);
                y++;
            }
            foreach (DataColumn dc in dt.Columns) {
                textColumn = new DataGridTextBoxColumn();
                textColumn.MappingName = dc.ColumnName;
                textColumn.HeaderText = "" + dc.Caption;
                textColumn.Width =
		Convert.ToInt32(Convert.ToSingle(cWidths[dc.Ordinal]));
                DGStyle.GridColumnStyles.Add(textColumn);
                sumWidths += textColumn.Width;
            }
            dg.TableStyles.Add(DGStyle);
        }
    }
}

Example of one of the many asynchronous WebService calls:

C#
// This code is in the tabMain_SelectedIndexChanged event of the frmMain class
PocketCatalogue.SyncService.MusicCatalogueSync wsSync =
		new PocketCatalogue.SyncService.MusicCatalogueSync();
AsyncCallback cbDisc = new AsyncCallback(ServiceCallback_DiscCount);
wsSync.BeginGetDiscCount(cbDisc, wsSync);

// This code is in the frmMain class
private void ServiceCallback_DiscCount(IAsyncResult ar) {
    try {
        PocketCatalogue.SyncService.MusicCatalogueSync wsSync =
		(PocketCatalogue.SyncService.MusicCatalogueSync)ar.AsyncState;
        this.lblDiscsServer.Text = wsSync.EndGetDiscCount(ar).ToString();
        bDiscCountReturned = true;
        if ((bDiscCountReturned) && (bAlbumCountReturned) && (bTrackCountReturned)) {
            this.cmdSync.Enabled = true;
            this.lblStatusMessage.Text = "";
            tmrProgress.Enabled = false;
        }
    } catch (Exception) {
        MessageBox.Show("Error terminating Web Service call", this.Text);
        tmrProgress.Enabled = false;
    }
}

Points of Interest

This was my first Pocket PC Application and I really enjoyed it, and I plan on doing many more. I learned lots of things from this little project including threading on a mobile device, SqlCE database technologies and Asynchronous WebService access.

History

  • Version 1.0, September 21 2005

Coming Soon

  • Version 1.1 will include the create statements necessary for making the corresponding Server MySQL Database
  • Version 1.2 will include the code for the WebService being used

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionPC version? Pin
Alan Holden28-Apr-14 2:50
Alan Holden28-Apr-14 2:50 
GeneralUnable to download the source code Pin
ravi42213-Apr-07 22:22
ravi42213-Apr-07 22:22 
GeneralExtend or port project to support MP3 Tunes service Pin
daluu28-Feb-07 15:55
daluu28-Feb-07 15:55 
Great project. It might be neat if someone could extend this project or port it to support the MP3 Tunes online streaming music locker service. The basic locker account is free and they have a free open API for this called the Oboe API. Also see the MP3 Tunes site for details on what you can do with the locker account.

I plan to take a shot at this when I get a chance, but thought I'd share the idea in case I never get to it.


"A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible." - Freeman Dyson

Generalrecompiling to wm5 device Pin
boxman128-May-06 10:06
boxman128-May-06 10:06 
GeneralRe: recompiling to wm5 device Pin
boxman110-Jun-06 9:22
boxman110-Jun-06 9:22 
GeneralInstall help Pin
matteof8-Jan-06 0:24
matteof8-Jan-06 0:24 
QuestionWhere I can find webservices ? Pin
noce2k4-Jan-06 5:28
noce2k4-Jan-06 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.