-1

I am currently working on a simple solo project to find and continuously play songs off of my machine, one after the next. The music is in various formats that I have downloaded.

MP4, MP3, MPEG, AVI, and WAV

Everything works from recursively searching the specified directory for music to playing the file and creating playlists. But I cannot seem to figure out how to find the length of these files in order to determine how long the program should wait before proceeding to another song.

I am building this program using Unity3d on a Windows 8 HP Laptop. Any input is appreciated.

Michie S
  • 1
  • 2
  • 4
    look this question. http://stackoverflow.com/questions/18602652/getting-mp3-file-length – ciro Jan 14 '16 at 17:27
  • So it looks like Microsoft.WindowsAPICodePack.Shell is the library used for this code. I've gone and downloaded the dll for it but where can I install it to be used in my project? – Michie S Jan 15 '16 at 19:37
  • Propose this be re-opened, as the 'duplicate' question is about a very specific library, BASS, and this is about Unity3D, which has a totally different set of libraries. – Rushyo Sep 17 '16 at 19:48

2 Answers2

0

If you're using Audioclip, you can use this : http://docs.unity3d.com/ScriptReference/AudioClip-length.html http://docs.unity3d.com/ScriptReference/AudioSource-isPlaying.html

As @Wai Ha Lee suggested, I should add some explanations with the link, so here it is. You can use the AudioClip.Length and AudioSource.IsPlaying (documentation linked above) in order to get the necessary informations.

Stud
  • 521
  • 4
  • 8
  • Thanks, but the files I am playing are external to the Unity project. Since they are so many different formats like mp3, mp4, etc. I am playing the songs with Media Player instead of streaming them into Unity. – Michie S Jan 15 '16 at 19:38
0

As stud said, for audio files in Unity, use AudioClip.Length. And then for video data, you should use MovieTexture.Duration class.

Working with media files in C# can sometimes (even in 2015) still be a pain point, so my advice is to utilise libraries like TagLib where possible. If libraries like TagLib are overkill, then look into their source and take the bits you need.

Neville
  • 413
  • 5
  • 6