
' functions to play audio files (mid, wav, mp3)
' http://www.freebasic-portal.de/code-beispiele/

#include once "windows.bi"
#include once "win/mmsystem.bi"

function FB_MCI(byval fb_command as string, byval f_alias as string) as integer
    dim temp as string*256
    f_alias = uCase(f_alias)
    select case lCase(trim(fb_command))
      case "play", "on", "an"
          mciSendString("play " & f_alias & " from " & 0, null, 0, 0)
      case "close", "off", "aus"
          mciSendString("close " & f_alias, null, 0, 0)
      case "stop"
          mciSendString("stop " & f_alias, null, 0, 0)
      case "length", "len"
          mciSendString("status " & f_alias & " length", temp, 256, 0)
          FB_MCI = val(temp)
      case "position", "pos"
          mciSendString("status " & f_alias & " position", temp, 256, 0)
          FB_MCI = val(temp)
    end select
end function

function FB_MCI_open(byval f_name as string, byval f_alias as string) as integer
    f_alias = uCase(f_alias)
    FB_MCI ("close", f_alias)
    FB_MCI_open = mciSendString("open " & chr(34) & f_name & chr(34) & " alias " & f_alias, null, 0, 0)
    mciSendString ("set " & f_alias & " time format milliseconds", null, 0, 0)
end function
