Click here to Skip to main content
15,891,864 members
Articles / Mobile Apps / Windows Mobile

Audio Book Player

Rate me:
Please Sign up or sign in to vote.
4.86/5 (36 votes)
11 Jun 2009CPOL6 min read 198.2K   3.5K   84  
Audio player designed specifically for listening to audio books
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Runtime.InteropServices;

public enum eBookProperty
{
    BOOKMARK_ENTRY = 0,
    BOOKMARK_LOCATION = 1,
    VOLUME = 2,
    SHUFFLE = 3
};
public enum eTagNames
{
    ALBUM = 0,
    TITLE = 1,
    AUTHOR = 2,
    COMMENT = 3,
    FILE_NAME = 4
};
public enum ePlayerStatus
{
    UNDEFINED = 0,
    STOPPED = 1,
    PAUSED = 2,
    PLAYING = 3,
    SCAN_FORWARD = 4,
    SCAN_REVERSE = 5,
    BUFFERING = 6,
    WAITING = 7,
    MEDIA_ENDED = 8,
    TRANSITIONING = 9,
    READY = 10,
    RECONNECTING = 11
};
public struct PowerState
{
    public bool ACLineConnected;
    public byte BatteryLifePercent;
    public PowerState(bool ac, byte life)
    {
        ACLineConnected = ac;
        BatteryLifePercent = life;
    }
};
// declare event handlers
public delegate void PlayItemChangedEventHandler(object sender, PlayItemChangedEventArgs e);
public delegate void StatusChangedEventHandler(object sender, StatusChangedEventArgs e);
// declare event class for play item changed
public class PlayItemChangedEventArgs : EventArgs
{
    private int pItemIndex;
    public int ItemIndex
    { get { return pItemIndex; } }
    public PlayItemChangedEventArgs(int i) { pItemIndex = i; }
}
// declare event class for play status changed
public class StatusChangedEventArgs : EventArgs
{
    private ePlayerStatus pStatus;
    private String pStatusText;
    public ePlayerStatus Status
    { get { return pStatus; } }
    public String StatusText
    { get { return pStatusText; } }
    public StatusChangedEventArgs(ePlayerStatus e, String s)
    { pStatusText = s; pStatus = e; }
}
public abstract class cBasePersistancy
{
    [DllImport("coredll.dll")]
    public extern static int GetDiskFreeSpaceEx(
    string lpRootPathName, ref Int64 lpFreeBytesAvailableToCaller,
    ref Int64 lpTotalNumberOfBytes, ref Int64 lpTotalNumberOfFreeBytes);

    public abstract String ActiveBookName { get; set; }
    public abstract String Skin { get; set; }
    public abstract int GetBookProperty(eBookProperty prop, String book);
    public abstract bool SetBookProperty(eBookProperty prop, int value, String book);
    public abstract String[] Books { get; }
    public abstract String[] Bookshelves { get; }
    public abstract String[] GetBookshelfBooks(String bookshelf);
    public abstract String GetBooksBookshelf(String book);
    public abstract bool NewBookshelf(String bookshelf);
    public abstract bool DeleteBookshelf(String bookshelf);
    public abstract bool SetBooksBookshelf(String book, String newBookshelf);
    public abstract bool NewBook(String book, String bookshelf);
    public abstract int GetBookFileCount(String book);
    public abstract String[] GetBookFiles(String book);
    public abstract bool SetBookFiles(String[] newFiles, String book);
    public abstract bool DeleteBookFile(int ix, String book);
    public abstract bool DeleteBookFiles(String book);
    public abstract bool RenameBookShelf(String newName, String bookshelf);
    public abstract bool RenameBook(String newName, String book);
    public abstract bool DeleteBook(String book);
    // unique item
    public String MakeUnique(String item)
    {
        ArrayList list = new ArrayList();
        list.AddRange(Books);
        list.AddRange(Bookshelves);
        for (int i = 0; i < list.Count; i++)
            list[i] = ((String)(list[i])).ToUpper();
        if(list.IndexOf(item.ToUpper()) == -1) return item;
        int n = 1;
        String newName = "";
        do
        {
            n++;
            newName = item + " (" + n.ToString() + ")";
        } while (list.IndexOf(newName.ToUpper()) != -1);
        return newName;
    }
    // find storate card with largest capacity
    public String GetLargestStorageCard()
    {
        Int64 HighCapacity = 0;
        String StorageCard = "";
        DirectoryInfo[] root = new DirectoryInfo(@"\").GetDirectories();
        foreach (DirectoryInfo dir in root)
        {
            if ((dir.Attributes & FileAttributes.Temporary) != 0)
            {
                Int64 notNeeded1 = 0;
                Int64 notNeeded2 = 0;
                Int64 CardCapacity = 0;
                GetDiskFreeSpaceEx(dir.FullName, ref notNeeded1,
                    ref CardCapacity, ref notNeeded2);
                if (CardCapacity > HighCapacity)
                {
                    HighCapacity = CardCapacity;
                    StorageCard = dir.FullName;
                }
            }
        }
        return StorageCard;
    }
}
public abstract class cBaseDeviceSpecifics
{
    public abstract int Volume { get; set; }
    public abstract long PowerOffThreshold { get;}
    public abstract PowerState PowerAndBatteryState { get;}
    public abstract int BacklightTimeout { get; set; }
    public abstract void Beep();
    public abstract void PreventAutoPowerOff();
    public abstract void PowerOff();
}
public abstract class cBasePlayer
{
    public abstract ePlayerStatus Status { get; }
    public abstract String StatusString { get;}
    public abstract bool Shuffle { get; set; }
    public abstract int Duration { get;}
    public abstract String DurationString { get; }
    public abstract int Location { get; set; }
    public abstract String LocationString { get; }
    public abstract int TotalDuration { get; }
    public abstract String TotalDurationString { get;}
    public abstract int TotalDurationSoFar { get;}
    public abstract String TotalDurationSoFarString { get; }
    public abstract int TotalDurationRemain { get;}
    public abstract String TotalDurationRemainString { get;}
    public abstract int PlaylistCount { get; }
    public abstract int PlayingIndex { get; set; }
    public abstract String PlayingPath { get;}
    public abstract String PlayingName { get;}
    public abstract void Dispose();
    public abstract String PlaylistFile(int i);
    public abstract int FileDuration(int i);
    public abstract int RemoveAt(int ix);
    public abstract String GetMediaTAG(eTagNames tag);
    public abstract bool Play();
    public abstract bool Pause();
    public abstract bool Next();
    public abstract bool Previous();
    public abstract bool Stop();
    public abstract bool StopAndClear();
    public abstract bool Playlist(String[] files, int Entry, int Location, bool Shuffle);
    public abstract bool WaitForPlayerStatus(ePlayerStatus s);
    public abstract String TimeToString(int time);
    public abstract String TrimTimeString(String str);
    public abstract void GetTotalsDurationsThreadFunction();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


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

Comments and Discussions