Click here to Skip to main content
6,595,444 members and growing! (19,387 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » GDI+     Beginner License: The Code Project Open License (CPOL)

iPod touch UI

By Dr.Luiji

It's a Media Player that work with transparency effects, also play mp3 and wav files, display the tag if present and display the album art image if present.
C# (C# 2.0), Win Mobile (PocketPC 2002, WinMobile2003, WinMobile5, WinMobile6), .NET CF, GDI+, COM, WinForms
Version:32 (See All)
Posted:6 Jan 2009
Views:17,458
Bookmarked:75 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
21 votes for this article.
Popularity: 6.11 Rating: 4.62 out of 5

1

2
2 votes, 9.5%
3
3 votes, 14.3%
4
16 votes, 76.2%
5

Download iPodTouch_UI.zip - 151.72 KB

SampleImage2.gif

Contents   

Introduction      

It's a Media Player that works with transparency effects, also it's play mp3 and wav files, display the tags if present and display the album art image if present.   

Original Media Player user interface is impossible to control using your finger. Here I have tried to solve also this problem.

As a sample I used an interface just like the iPod touch one. In this tutorial mostly I continue to explaining a better way to work with transparency on Windows Mobile.  For a beginning introduction to this article I suggest to you to read before my previous article on transparency iPhone UI[^].

In this article you can also read about: 

  • Resolution-aware and Orientation-aware  
  • Dynamic graphic text resize  
  • Mouse gesture   
  • Intercepting button  
  • Work with Windows Media Player OCX on Windows Mobile.    

Background  

I found some problem with sound files in particular for retrieving the tag info and the current position time, after a long search, I choose to use the the Windows Media Player OCX. The article Audio Book Player [^] by brochpirate give you a fast way to use the OCX on Mobile trough the OpenNETCF.org, it's a great working sample. Hereunder I explain a bit how you can play with it.  

How to work with WMP   

To use the Windows Media Player only you need to import this dll as reference:  

  • OcxControls
  • OpenNETCF.Windows.Forms.AxHost  
  • WMPLib   

And add the cPlayer to your app. Now you are ready to get control of WMP, really cool, isn't it?   

Using the code  

The solution  

Going deep into the solution you can find  

  • iPlayer class, the main form with: Resolution-aware, dynamic graphic text resize, mouse gesture, and work also with Windows Media Player COM .
  • cPlayer class, this class work with Media Player OCX, it's under the abPlayer. I add only few property the loop and the volume 
  • FilesManger class, this class get all the mp3 and Wav files of your mobile device.
  • ImageButtons class, a class button with transparency  and other stuff
  • PlatformAPIs class, it is the class to manage the P/Invoke  
  • SlideButton class, the class that move the Image (progress). 
  • BMPs folder, it contains all the BMP  used in the code  

iPlayer class  

This is the main form of the app.  I paint all the form in the method myPaint(Graphics dc). The myPaint can be called from the Paint eventhandler and use the e.Graphics or can be called when a state change and the  dc used is the CreateGraphics(). The my paint draw all the screen with all the control inside, begin with the background, the TopBar, the SongBar, LocationBar (if needed),  BottomBar, and the various button used. 

The Background   

The bitmapBackImage Bitmap is load as background and  the default image of the first image found in the song directory. To choose the image I preferred to display the "Folder.jpg" if exist because is the default used by the default internet CD searching. 

this is the code

private void SearchBGImage()
{
    if (FormListScanFiles.lvwSoundFiles.Items.Count != 0)
    {
        string path = Player.PlayingPath.Remove(Player.PlayingPath.LastIndexOf(@"\"), Player.PlayingPath.Length - Player.PlayingPath.LastIndexOf(@"\"));
        String[] ImageFiles = GetImageFiles(path);
        if (ImageFiles.Length != 0)
        {
            foreach (string ImageFile in ImageFiles)
            {
                //If you use the internet CD databases you can have more than a picture inside the folder
                //This method chooses the one that best fit screen
                if (ImageFile.Remove(0, ImageFile.LastIndexOf(@"\") + 1).ToLower() == "folder.jpg")
                {
                    bitmapBackImage = new Bitmap(ImageFile);
                    return;

                }
            }
            bitmapBackImage = new Bitmap(ImageFiles[0]);
            return;
        }
    }         
    bitmapBackImage = bitmapBackImageDefault;
}

The default image:

wallpaperDefault2.gif

 

If I need to stretch the image I used this code  

Rectangle srcRect = new Rectangle(0, 0, bitmapBackImage.Width, bitmapBackImage.Height);
Rectangle destRect = new Rectangle(0, 0, this.Width, this.Height);
gxBuffer.DrawImage(bitmapBackImage, destRect, srcRect, GraphicsUnit.Pixel); 

else I draw centre & unscaled  

int x = (this.Width - this.bitmapBackImage.Width) / 2;
int y = (this.Height - this.bitmapBackImage.Height) / 2;
gxBuffer.DrawImage(this.bitmapBackImage, x, y);

The Topbar 

This part is similar to the iPhone UI article but here I change the position of the images dimanically. The Topbar is divided in 4 images and the time text:  

  • the Battery level, with a left anchor with no stretch  
  • the timeline, with left anchor (the battery level width), right anchor (the GSM level width +
  • Current Player status width),  use the stretch  
  • Current Player status, with left anchor  (timeline  width+ battery level width), right anchor (the battery level width). no stretch 
  • the GSM level, with a right anchor with no stretch 
  • The time is drowned in the middle of the screen width and in the middle centred in the middle of the timeline ( timeline height/2- text height/2) 

All the images:    

  • Battery Level Bitmaps AllBatteryLevelBitmaps.gif
  • GSM Level Bitmaps     AllGSMLevel.gif
  • Top Player status        AllTopPlayerStatus.gif

and this two samples of the view: 

TopBar1.gifTopBar2.gif

The SongBar with text resize 

This part is a stretch of a single bitmap to all the width of the screen and with a fixed height.

This is the original bitmap: SongBar.gif

And these are two stretch samples:  

SongBarSample_.gif

Over it I put two ImageButton one for Exit and one for the files list. The buttons are centred in the middle of the SongTopBar bitmap height, and the exit has the left anchor, the right have the right anchor.  

In the middle of the screen I put the Artist name, the song name and the album name. The strings are the tags retrieved from the current file selected.  

Here I use my DynamicGraphicTextResizing for a "Dynamic graphic text resize" If the width of the displayed string is much greater than the display width I modify the string with the minimum size that fit the screen weight and i add to the end "..."   

private void DynamicGraphicTextResizing(ref string text, ref SizeF size, Font songTitleFont)
{
    while (size.Width > this.Width - buttonExit.Image.Width - buttonList.Image.Width)
    {
        text = text.Remove(text.Length - 4, 4);
        text = text + "...";
        size = gxBuffer.MeasureString(text, songTitleFont);
    }
} 

To draw the string I use this code:  

string title = Player.GetMediaTAG(eTagNames.TITLE); 

SizeF sizeTitle = gxBuffer.MeasureString(title, FontsongTitle);
DynamicGraphicTextResizing(ref title, ref sizeTitle, FontsongTitle);
xSong = this.Width / 2 - (int)sizeTitle.Width / 2 + buttonExit.Image.Width / 2;
gxBuffer.DrawString(title, FontSong, BrushWhite, xSong, bitmapTopHeader.Height + sizeTitle.Height - 2);

 

Info.png Info: brochpirate in his article add a way to scroll the text. Take a look there, I think you can find it useful.

This are all the images used:   

 SongTopbar.gif

This is a sample on how it works:   

SongBarSample2.gif

The LocationBar     

Info.png Info:  This part is showed only if the users click on the SongBar, it dispaly the current location, the song duration, and a progress bar for the current location.

To show the Location bar I useuser an internal bool value  ShowTimeLine and I decide to draw it  if you click over the SongBar. When the LocationBar is showed it enable a timer every second to draw the current location and to draw the step for the progress.   

private bool SongMouseUp(MouseEventArgs e)
{
    if (ClientAreaSong().Contains(e.X, e.Y))
    {
        ShowTimeLine = !ShowTimeLine;
        timerDrawLocation.Enabled = SetTimerDrawLocation();
        return true;
        }
    return false;
}
The LocationBar is divided in 8 parts.  
  • Repeat button with 2 state, pressed On, Off 
  • Current Location time + the background 
  • Progress of the song is divided in 2 part the played and not played 
  • Duration time + the background 
  • Shuffle button with 2 state , pressed On, Off 

Note: Here I’ve not covered everything in algorithm but I believe that you will understand these easily. 

The Repeat button is set to the WMP repeat state. The anchor is left and it's not stretched.

The current location time and the duration time are string retrieved from the player Player.LocationString Player.DurationString. The Back ground image are this: 

The progress is divided in 2 part the played and not played, I use two image and I calculate the location position on the screen iWidthProgressPlayed. After I draw the PalyedProgress from a fixed start to the iWidthProgressPlayed and the NotPalyedProgress from  iWidthProgressPlayed with a dynamic width (all the size possible less than played) iWidthTotal - iWidthProgressPlayed.

The Shuffle button is set to the WMP repeat state. 

All the images used:  

AllTimelineBitmaps.gif   

These are 3 samples on how it works:

LocationBarSample.gif 

LocationBarSample3.gif

Warning.png Attention:  I tried the app under few devices and sometime I found it slow, I suggest to you to use the LocationBar only if needed. The program starts with the LocationBar Hided.

Middle of the screen    

If the search doesn't find a file (mp3 or wav) it displays a text in the middle of the screen "No files found". 

This is the code:   

private void DrawSongNumber(Graphics gx)
{
    if (FormListScanFiles.lvwSoundFiles.Items.Count == 0)
    {
        NoFilesFound = "No files found";
        SizeF sizeNoFilesFound = gxBuffer.MeasureString(songname, FontSongNoFilesFound);
        int xSong = this.Width / 2 - (int)sizeNoFilesFound.Width / 2;
        int ySong = this.Height / 2 - (int)sizeNoFilesFound.Height / 2;

        int widthMessage = (int)sizeNoFilesFound.Width ;
        int xMessage = (this.Width / 2 - (int)widthMessage / 2 )-10;
                
        int yMessage = this.Height / 2 - (int)bitmapMessage.Height / 2;

        DrawAlphaStretchX(gxBuffer, bitmapMessage, 170, xMessage, yMessage, widthMessage);
                
        gxBuffer.DrawString(NoFilesFound, FontSongNoFilesFound, BrushWhite, xSong, ySong);
    }
}

and this is a sample

FilesNotFound2.gif

 

The Bottom bar      

For the bottom I used a large background with the left anchor and the right anchor.

The bitmap is divided in two section (the first half and the second half).

In the first half I put the Player controls: previous, Play/Pause, Next. these images are stored in three ImageButton. Also the player status is over in the Topbar.

The second half contain the volume slide, it's a SlideButton. Here I add a modifyed on the previous posted in the iPphone UI. I add possibily to interact with the progress, and set it with a percentage. When the mouse is moved over the Slide button the volume change and it display the percentage is similar to the used in the location bar.
these are all the entire image used:

AllBottomBitmaps.gif 

these are two samples: 

BottomBarSample.gif

Points of Interest   

I would like to remind that this program is not a complete interface. This article adds some features used in to the iPhone UI and I hope you find useful.  

Note: I believe that the article contains some translation errors, please humour me and go ahead reading the article. Soon I'll translate it better. 

Links      

  • Audio Book Player here[^], many thanks for your help BrochPirate.
  • The Hosting ActiveX Controls in the .NET Compact Framework 2.0  here[^]
  • The introduction of this article iPhone UI[^]   
  • History  

    • 7 Gen 2009 - First release.  
    • 10 Gen 2009 - Second release.   
    Minor bug fixing, Hided the LocationBar at the start, added the Message bitmap. 

        

    License

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

    About the Author

    Dr.Luiji


    Member
    Bertoneri Luigi, alias Dr.Luiji
    Bachelor of Science in Computer Science, year 2K - University of Pisa (Italy).

    I'm a developer with more than 10 years of experience. I like the new technology, especially of Windows Vista, Windows Mobile and Windows Embedded.
    I love challenges.

    Skills:
    - Language: C++ (VC6, VC8), C#
    - Platform: Windows (Win98, WinNT, Win2000, WinXP, Win2003, Vista, Mobile, CE), .NET (.NET 2.0, .NET 3.0), .NETCF, .NET Micro
    - Technology: Win32, Visual Studio (VS2005, VS2010), MFC, COM, ADO, WinForms, WebForms, XML, CSS, MySql, Skype (API), WinAmp (API), CNG, Sidebar, Sideshow, gSOAP & Web Services, NSIS, OpenSSL, Tapi v2-3, Socket, Zlib, E-mail & SMTP, Crystal Reports, XML, HTML, Threads, Shell programming, FTP, TFTP, Registry, Alarm, NT Service, MailSlot, Splitter, Crypto++, id3lib, ResizableLib, etc.

    I currently work and live in Italy.
    Music I listen to: Slipknot, Dope, Tool, NIN, Korn, Dry Kill Logic, Godsmack, System of a Down, White Zombie, Pantera, Soil, RA, Mushroomhead, Slayer, Oteph, Therion, Machine head, Disturbed, Lamb of God, Type O Negative, and more.
    Occupation: Software Developer (Senior)
    Company: TELCEN s.p.a.
    Location: Italy Italy

    Other popular Mobile Development articles:

    • Writing Your Own GPS Applications: Part 2
      In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
    • Writing Your Own GPS Applications: Part I
      What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
    • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
      A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
    • iPhone UI in Windows Mobile
      It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
    • Pocket 1945 - A C# .NET CF Shooter
      An article on Pocket PC game development
    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
    GeneralTerrific. Pinmembervictorbos5:39 7 Nov '09  
    GeneralRe: Terrific. PinmemberDr.Luiji8hrs 50mins ago 
    GeneralGood Job PinmemberPavanPareta7:31 9 Aug '09  
    GeneralRe: Good Job PinmemberDr.Luiji8:38 10 Aug '09  
    GeneralGood job PinmemberJustx23:36 27 Jul '09  
    GeneralRe: Good job PinmemberDr.Luiji3:28 28 Jul '09  
    GeneralDrawSongName thows exception PinmemberVIJAY15107:10 30 Apr '09  
    GeneralRe: DrawSongName thows exception PinmemberDr.Luiji2:08 4 May '09  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 6 Jan 2009
    Editor:
    Copyright 2009 by Dr.Luiji
    Everything else Copyright © CodeProject, 1999-2009
    Web17 | Advertise on the Code Project