Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF C#, Get informations from audio file
    text
    copied!<p>Hy!<br> I'd like to get some informations from an audio file (title, artist, etc.) in C# (wpf). The MediaElement doesn't provides this option, so I used this code (read bytes directly):</p> <pre><code>public string[] GetAudioFileInfo(string path) { path = Uri.UnescapeDataString(path); byte[] b = new byte[128]; string[] infos = new string[5]; //Title; Singer; Album; Year; Comm; bool isSet = false; //Read bytes try { FileStream fs = new FileStream(path, FileMode.Open); fs.Seek(-128, SeekOrigin.End); fs.Read(b, 0, 128); //Set flag String sFlag = System.Text.Encoding.Default.GetString(b, 0, 3); if (sFlag.CompareTo("TAG") == 0) isSet = true; if (isSet) { infos[0] = System.Text.Encoding.Default.GetString(b, 3, 30); //Title infos[1] = System.Text.Encoding.Default.GetString(b, 33, 30); //Singer infos[2] = System.Text.Encoding.Default.GetString(b, 63, 30); //Album infos[3] = System.Text.Encoding.Default.GetString(b, 93, 4); //Year infos[4] = System.Text.Encoding.Default.GetString(b, 97, 30); //Comm } fs.Close(); fs.Dispose(); } catch (IOException ex) { MessageBox.Show(ex.Message); } return infos; } </code></pre> <p>The problem with this code, that sometimes it doesn't gives the full title or represents only little cubes. (If I open the media in MeidaPlayer, than I can see the full title)<br> I'm not sure the parameters of the GetString(byte[],int,int), maybe I make mistakes there.</p> <p>In my prgram: <img src="https://i.stack.imgur.com/7UCgo.png" alt="This is the result"><br> In media player: <img src="https://i.stack.imgur.com/7NB3F.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload