Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / Windows Forms

MP3 Playlist creator for Opel Ampera and Chevy Volt

Rate me:
Please Sign up or sign in to vote.
4.78/5 (8 votes)
23 Jul 2016CPOL3 min read 23.7K   763   5   2
Explains the issues of the mp3 player in the Ampera and Volt and how the playlist creator can solve this.

Background

The multimedia entertainment system in the Opel Ampera and Chevy Volt has some peculiarities when playing MP3 tracks from a USB stick and built-in hard drive for example it doesn't recognize Windows folder hierarchy. When a folder with different genres and albums of mp3 files is copied to the Ampera's hard drive; one flat list of mp3 and folder names is shown but no sign of the original genre and album hierarchy. For example, when I arrange music like in the next picture, it will be arranged as a flat list of folders and mp3 names in the Ampera's mp3 player.

Image 1

When playing directly from the USB stick, the folder hierarchy is recognized but still some oddities are left. When playlist files are piggy bagged with the copy process, the player makes a mess of it. It doesn't know to choose between the folder hierarchy or the playlist files for displaying the mp3 files. When only using folder hierarchy without playlist files, again strange things happen, especially when the hierarchy is deep and the number of folders is greater then about 50. For example, it loses track of the mp3 locations and skipping a mp3 track can give surprising effects like suddenly jumping to another album or jumping back to the first mp3 track of the same or even another album.

After reading some forums, I found out that the best way to deal with the Ampera's mp3 player is to only use playlist files and copy all mp3 files with the playlists to the root of the USB stick. Because this is quite a repetitive process, I made a small program to do this in an more easy manner.

The Application

The application works as follows: Choose a folder where the mp3 files are arranged in folder hierarchy style, e.g., Rock\British\Rolling Stones. Choose a target folder, for example the drive mapped to the USB stick and you are ready to go. The application will create all playlist files and copies all mp3 tracks with the corresponding playlist files to the USB stick in such a manner that the Opel Ampera and Chevy Volt is able to (dis)play the mp3 tracks.

Image 2

The application is using UltraID3Lib to handle the mp3 tracks. A very easy and pleasant library for reading and writing ID3 metadata in MP3 file Check: UltraID3Lib.

The code of the Playlist creator is also quite straight forward, it reads in an iterative way through all folders and collects all mp3 data. The playlists are created and named depending on the folder where the mp3 data is located. After collecting all data, the mp3 tracks and corresponding playlists are copied to the target folder.

C#
private string CreatePlayList(string folder)
{
	UltraID3 ultraId = new UltraID3();
	StringBuilder stringBuilder = new StringBuilder();

	string[] files = Directory.GetFiles(folder, "*.mp3", SearchOption.TopDirectoryOnly);
	if (files.Count() != 0)
	{
		ShowMessage(string.Format("Reading tracks from :  {0} ", folder));
		int entryNumber = 0;

		stringBuilder.AppendLine("[playlist]");

		foreach (string fileName in files)
		{
			ultraId.Read(@fileName);
			int lenght = Convert.ToInt32(ultraId.Duration.TotalSeconds);
			megaBytes = megaBytes + ultraId.Size / 1000000;

			if (megaBytes > maxNumberOfMB && maxNumberOfMB > -1)
			{
				numberOfMBExceeded = true;
				megaBytes = megaBytes - ultraId.Size / 1000000;
				break;
			}
			numberOfTracks = numberOfTracks + 1;
			if (numberOfTracks > maxNumberOfTracks && maxNumberOfTracks > -1)
			{
				numberOfTracksExceeded = true;
				numberOfTracks = numberOfTracks - 1;
				break;
			}
			entryNumber = entryNumber + 1;
			string title = ultraId.Title;
			stringBuilder.AppendLine(string.Format("File{0}={1}", 
				entryNumber, Path.GetFileName(fileName)));
			stringBuilder.AppendLine(string.Format("Title{0}={1}", entryNumber, title));
			stringBuilder.AppendLine(string.Format("Length{0}={1}", entryNumber, lenght));
		}
		stringBuilder.AppendLine(string.Format("NumberOfEntries={0}", entryNumber));
		stringBuilder.AppendLine("Version=2");
	}
	return stringBuilder.ToString();
}

Still some Ampera/Volt mp3 player peculiarities have to be taken into account:

  • Sometimes no more than 1000 tracks are displayed.
  • No more than 200 tracks are displayed per playlist.

At this moment, the code works only with mp3 files but can be easily adapted to work with other music files. Best usage is to create relatively many playlists with a small number of mp3 tracks (less than 100) per playlist. Doing so makes the Ampera and Volt happy.

License

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


Written By
Founder Rood Mitek
Netherlands Netherlands
Christian Vos .MCSD has been an independent Microsoft developer since 1999 and is specialized in distributed Microsoft .Net platform based Web applications. He is founder of the company Rood Mitek which has developed applications for companies like Philips Electronics, ASML, Lucent Technologies, Amoco, AT&T etc.

Comments and Discussions

 
PraiseGreat, thanks! Pin
Member 1273138613-Sep-16 10:56
Member 1273138613-Sep-16 10:56 

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.