Jump to content

media files


Recommended Posts

is there any way how i can check the lenght of a audio file??

i'made a media player, but i need the lenght of the file for my progress bar and the repead function.

(i'll post the media player when you ask for it)

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

#include <GuiConstants.au3>
Opt("GUIoneventmode",1)
Opt("OnExitFunc","_write")
Global $songname[500]
Global $song[500]
Global $songGUI[500]
Global $number
;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("Media Player", 336, 168,(@DesktopWidth-336)/2, (@DesktopHeight-168)/2,-1,0x00000018)
$Input = GuiCtrlCreateInput("Drag And Drop Media files here.", 120, 10, 210, 20)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
$Listname = GUICtrlCreateListView ( "Playlist|path",10,10,100,149)
_Loadplay()
$Slider = GuiCtrlCreateSlider(110, 130, 190, 40)
$Buttonplay = GuiCtrlCreateButton("Play", 120, 30, 70, 30)
$Buttonstop = GuiCtrlCreateButton("Stop", 120, 60, 30, 30)
$Buttonadd = GuiCtrlCreateButton("Add", 150, 60, 30, 30)
GUICtrlSetData($Slider,100)
GUICtrlSetLimit ($Slider,100,0)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GuiCtrlSetOnEvent($ButtonPlay, "_Play")
GuiCtrlSetOnEvent($Buttonstop, "_Stop")
GuiCtrlSetOnEvent($Buttonadd, "_Add")
GuiSetState()

While 1
    SoundSetWaveVolume (GUICtrlRead($slider))
WEnd

Func _Exit()
    Exit
EndFunc
Func _play()
    $song = StringSplit (GUICtrlRead($input), "|")
    if $song[0] = 1 Then
    SoundPlay($song[1])
Else
    SoundPlay($song[2])
EndIf
EndFunc
Func _Stop()
    SoundPlay ("")
EndFunc
Func _loadplay()
    $number = IniRead ( "playlist.ini", "NUMBER", "number", "0" )
    If $number > 0 Then
        For $num=1 to $number
            $songname[$num] = IniRead ( "playlist.ini", "NAME", "name"&$num, "Not found" )
            $song[$num] = IniRead ( "playlist.ini", "PATH", "path"&$num, "Not found" )
            $songGUI[$num] = GUICtrlCreateListViewItem ($songname[$num]&"|"&$song[$num],$listname)
        Next
    EndIf
EndFunc

Func _Add()
    $adder = GUICtrlRead($input)
    $check = Stringsplit($adder,"|")
    If $check[0] = 1 Then
        $name = InputBox("Name","What is the songs name? (***.mp3/***.wma..)")
        $number=$number+1
        GUICtrlCreateListViewItem ($name&"|"&$adder,$listname)
        IniWrite ( "playlist.ini", "NUMBER", "number",$number)
        IniWrite ( "playlist.ini", "NAME", "name"&$number,$name)
        IniWrite ( "playlist.ini", "PATH", "path"&$number,$adder)
    Else
        GUICtrlCreateListViewItem ($adder,$listname)
    EndIf
EndFunc

its nr. 3 of the pet program project

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

van somebody pleas???? helpp me here.

i hope there is a way to check howlong the music files are

axample 4.67 min

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

does that HAS to be a wav??

because here it doesn't work with wma.

EDIT:

@lazycat: i'm testing urs now

Edited by zeroZshadow
*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

ALRIGHT!! works great!!

only it gives no time when u use mp3's

and lazycats mp3 tag and info reader olny work when the mp3's HAVE info or tag (mine don't)

i added a repeat function now (wich i'm testing right now) and a progressbar.

special thanks to larry!!

p.s. i know my english is bad

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

mmm.. strange it works now, but the other song didn't?!?!

This is the whole code now, but its still pretty buggy i think.

Isn't there an timerstop function?? strange

#include <GuiConstants.au3>
Opt("GUIoneventmode",1)
Opt("OnExitFunc","_write")
Global $songname[500]
Global $song[500]
Global $songGUI[500]
Global $number
Global $timer
Global $timestop
Global $playing = 0
GuiCreate("Media Player", 336, 168,(@DesktopWidth-336)/2, (@DesktopHeight-168)/2,-1,0x00000010)
$Input = GuiCtrlCreateInput("Drag And Drop Media files here.", 120, 10, 210, 20)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
$Listname = GUICtrlCreateListView ( "Playlist|path",10,10,100,149)
_Loadplay()
$Slider = GuiCtrlCreateSlider(110, 130, 190, 40)
$Buttonplay = GuiCtrlCreateButton("Play", 120, 30, 70, 30)
$Buttonstop = GuiCtrlCreateButton("Stop", 120, 60, 30, 30)
$Buttonadd = GuiCtrlCreateButton("Add", 150, 60, 30, 30)
GUICtrlSetData($Slider,100)
GUICtrlSetLimit ($Slider,100,0)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GuiCtrlSetOnEvent($ButtonPlay, "_Play")
GuiCtrlSetOnEvent($Buttonstop, "_Stop")
GuiCtrlSetOnEvent($Buttonadd, "_Add")
$progbar = GUICtrlCreateProgress(120,90,200,20,$PBS_SMOOTH)
GuiSetState()

While 1
    sleep(10)
    $diff = TimerDiff($timer)
    $progressset = ($diff/$timestop*100)
    if $playing = 1 Then
        If $progressset >= 100 Then
            _play()
        EndIf
    EndIf
    GuiCtrlsetdata($progbar,$progressset,0)
    SoundSetWaveVolume (GUICtrlRead($slider))
WEnd

Func _Exit()
    Exit
EndFunc
Func _play()
    $song = StringSplit (GUICtrlRead($input), "|")
    if $song[0] = 1 Then
        $FileName = '"'&$song[1]&'"'
        mciSendString("Open " & $FileName & " alias MediaFile")
        mciSendString("Set MediaFile time format milliseconds")
        $answer = mciSendString("Status MediaFile length")
        mciSendString("Close MediaFile")
        $timestop = $answer;MsgBox(4096,"file length","length in milliseconds:  " & $answer/1000)
        $timer = TimerInit()
        SoundPlay($song[1])
    Else
        SoundPlay($song[2])
    EndIf
    Global $playing = 1
EndFunc
Func _Stop()
    Global $playing = 0
    $diff = TimerDiff($timer)
    SoundPlay ("")
EndFunc
Func _loadplay()
    $number = IniRead ( "playlist.ini", "NUMBER", "number", "0" )
    If $number > 0 Then
        For $num=1 to $number
            $songname[$num] = IniRead ( "playlist.ini", "NAME", "name"&$num, "Not found" )
            $song[$num] = IniRead ( "playlist.ini", "PATH", "path"&$num, "Not found" )
            $songGUI[$num] = GUICtrlCreateListViewItem ($songname[$num]&"|"&$song[$num],$listname)
        Next
    EndIf
EndFunc

Func _Add()
    $adder = GUICtrlRead($input)
    $check = Stringsplit($adder,"|")
    If $check[0] = 1 Then
        $name = InputBox("Name","What is the songs name? (***.mp3/***.wma..)")
        $number=$number+1
        GUICtrlCreateListViewItem ($name&"|"&$adder,$listname)
        IniWrite ( "playlist.ini", "NUMBER", "number",$number)
        IniWrite ( "playlist.ini", "NAME", "name"&$number,$name)
        IniWrite ( "playlist.ini", "PATH", "path"&$number,$adder)
    Else
        GUICtrlCreateListViewItem ($adder,$listname)
    EndIf
EndFunc
Func mciSendString($string)
   Local $ret
   $ret = DllCall("winmm.dll","int","mciSendString","str",$string,"str","","int",65534,"hwnd",0)
   If Not @error Then Return $ret[2]
EndFunc

hope it helps ya

btw i can't attach any mp3 here, because 1. its illegal (not that i care) 2. its to big

Edited by zeroZshadow
*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

and lazycats mp3 tag and info reader olny work when the mp3's HAVE info or tag

<{POST_SNAPBACK}>

Mp3 can have or have not tag, but it always have info, so it should get it. But for VBR files it's seems impossible to get length without scanning whole file. In the autoit this task will take ages...
Link to comment
Share on other sites

  • 1 year later...

this works for me...

$FileName = "c:\mediafile.wma"

mciSendString("Open " & $FileName & " alias MediaFile")

mciSendString("Set MediaFile time format milliseconds")

$answer = mciSendString("Status MediaFile length")

mciSendString("Close MediaFile")

MsgBox(4096,"file length","length in milliseconds:  " & $answer)
Func mciSendString($string)
   Local $ret
   $ret = DllCall("winmm.dll","int","mciSendString","str",$string,"str","","int",65534,"hwnd",0)
   If Not @error Then Return $ret[2]
EndFunc

one thing to consider... if the file path has spaces, you need quotes...

$FileName = '"c:\media file.wma"'

Lar.

Larry`s code with some basic math to convert Milliseconds to Mins & Seconds :)

$FileName = '"F:\My Shared Folder\MP3\Favs\Meetcam\Bob Seger - Mainstreet.mp3"'

mciSendString("Open " & $FileName & " alias MediaFile")

mciSendString("Set MediaFile time format milliseconds")

$answer = mciSendString("Status MediaFile length")

mciSendString("Close MediaFile")

$Mins = int($Answer/60000) 

$Seconds = int($Answer/1000)

$Secs = int($Seconds-($Mins*60))

MsgBox(4096,"file length","length in seconds: " &$Mins &":" &$Secs)


Func mciSendString($string)
   Local $ret
   $ret = DllCall("winmm.dll","int","mciSendString","str",$string,"str","","int",65534,"hwnd",0)
   If Not @error Then Return $ret[2]
EndFunc

Of course if its possible to change the format from MCIsendstring that would be better...

Or just use seconds for a progress bar.

How would you link the progress bar to the length of the song?

I`m thinking something like set a timer that counts down the song length and read that into the progressbar?

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Of course if its possible to change the format from MCIsendstring that would be better...

Or just use seconds for a progress bar.

How would you link the progress bar to the length of the song?

I`m thinking something like set a timer that counts down the song length and read that into the progressbar?

Doh!, sorry, I` did`nt read the main script before posting! :)

Sorry! :mellow:

2015 - Still no flying cars, instead blankets with sleeves.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...