Question

How do I convert (as an example):

Señor Coconut Y Su Conjunto - Introducciõn

to:

Señor Coconut Y Su Conjunto - Introducciõn

I've got an app that creates m3u playlists, but when the track filename, artist or title contains non ASCII characters it doesn't get read properly by the music player so the track doesn't get played.

I've discovered that if I write the track out as:

#EXTINFUTF8:76,Señor Coconut Y Su Conjunto - Introducciõn
#EXTINF:76,Señor Coconut Y Su Conjunto - Introducciõn
#UTF8:01-Introducciõn.mp3
01-Introducciõn.mp3

Then the music player will read it correctly and play the track.

My problem is that I can't find the information I need to be able to do the conversion properly.

I've tried the following:

    byte[] byteArray = Encoding.UTF8.GetBytes(output);
    foreach (Byte b in byteArray)
    {
        playList.Write(b);
    }

where playList = new StreamWriter(filename, false); but I just get a series of numbers output:

#EXTINFUTF8:76,83101195177111114326711199111110117116328932831173267111110106117110116111 - 731101161141111001179999105195181110

which I guess are the numerical values of the characters rather than the characters themselves.

It's been a while since I've done this low level character manipulation and I'm a little rusty.

UPDATE

I've now got:

    byte[] byteArray = Encoding.UTF8.GetBytes(output);
    foreach (Byte b in byteArray)
    {
        playList.Write(Convert.ToChar(b));
    }

to do the output and at first glance it appeared to be working. The file as seen in Notepad++ is showing the correct information. However, the first track still isn't being played.

Was it helpful?

Solution

You want the whole stream to be in UTF-8. Try:

StreamWriter playList = new StreamWriter(filename, false, System.Text.Encoding.UTF8);

Now, to write to the stream, just pass your String named output like this:

playList.Write(output);

The stream will now all be in the proper encoding, so you should also just be able to do something like:

playList.WriteLine("#EXTINFUTF8:76,Señor Coconut Y Su Conjunto - Introducciõn");

OTHER TIPS

well, try to write the encoding player expects. and it is utf8! (i guess)

byte[] bytesToWrite = Encoding.Utf8.GetBytes(yourString);

see that: #UTF8 in your sample?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top