Jump to content

UDF : Media Controls


CFire
 Share

Recommended Posts

I have made this UDF with the help of lod3n because i wanted a way to change the volume of output from my program without affecting the rest of the comuter's volume settings. when i found this it gave a ton more than just volume control. Hope you find it useful. It TOTALLY replaces any use of Sound.au3 that is needed in ur scripts. It uses a Windows Media Player Com Object to run everything. I gave an Example script along with it, but these functions are rather simple to use.

Edit: (4.12) Made The example script use a fileopendialog

Edit: (4.14) Corrected a bug due to the indexing of the StringSplit() function. I just add a '+ 1' at the end of line 203. Thanks birdofprey

Edit: (4.24) Changed the way the functions are called. You no longer need to call the Objcreate() function instead that is taken care of in a new function, WMStartPlayer(). The Object Variable is kept track of by WMMedia.au3. You still need to pass a Song Object when needed for certain Functions. When your script is Exiting, Run WMClosePlayer(). Only Opening and Closing the Player once seems to reduce the Constant increase in Memory used by the script. All the functions are the same minus the need to Pass the $pObj to it.

Downloads : (4.24) - 124

WMMedia.au3

WMMedia_Example.au3

Edited by CFire

[u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output.

Link to comment
Share on other sites

Hi,

nice seems to work!

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

It seems I found a bug ! :shocked: You need to modify line nr. 203 to $iState = $pObj.playState() + 1 in order to get it work properly.

It's just a workaround though, anyhow, the problem comes from StringSplit, that assigns to $array[0] the number of elements, and because of this the whole array is pushed one position... took me half a day to figure out why my script was "reporting" the currently playing script as being "paused" :( It took me that long, because I was rewriting my script, and... it was a lot to be rewritten.

One more thing. I get an error described here: Link in the "Transitioning" faze... After I click on the msgbox, the song starts playing though.

Link to comment
Share on other sites

it sounds like its a problem with your default sound device. both the sound.au3 and wmmedia.au3 use what ever default sound device windows has registered. if you have a sound card and also have an onboard sound device on your motherboard then disable the one you are not using. the onboard one can be disabled in your computer's bios settings. other than that .... i don't know what could be going wrong.

[u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output.

Link to comment
Share on other sites

This windows media object seems to be a resource hog... seeks for example are much more "difficult" now than with the Sound UDF.

On top of this the application I created is eating up more and more memory after each song it plays. More exactly, when it starts playing those files. It might be that I did something wrong, but, I presume that a WMCloseMedia is really needed here. Setting $pObj = 0 is not working. Trying to close the object this way after a song has been played and recreating it for each new song, made me end up with dozens of such objects. I now only create a... $pObj once and reuse the object but, the private bytes allocated for the application are still increasing on every "songload".

Edited by birdofprey
Link to comment
Share on other sites

very nice job man. I'm impressed. Opens all new doors for audio... now only if someone would come out with some amazing graphic UDFs. =]

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Link to comment
Share on other sites

This windows media object seems to be a resource hog... seeks for example are much more "difficult" now than with the Sound UDF.

On top of this the application I created is eating up more and more memory after each song it plays. More exactly, when it starts playing those files. It might be that I did something wrong, but, I presume that a WMCloseMedia is really needed here. Setting $pObj = 0 is not working. Trying to close the object this way after a song has been played and recreating it for each new song, made me end up with dozens of such objects. I now only create a... $pObj once and reuse the object but, the private bytes allocated for the application are still increasing on every "songload".

I looked into this a bit further than i had before. I looked to see if there was a way to even close or delete the object but all i found was that the Object variable assigned by the ObjCreate() function is just a pointer to an object not the object itself. And i also found this in the Autoit help file about objects

Object variables behave a bit different than other types of AutoIt variables. An Object is not a real value, but a 'pointer' to something outside the script. So you can't perform arithmetic's, nor equations on Object variables. When you assign an Object variable a different value, the 'pointer' will automatically be released. You can, for instance, force deletion of an Object by assigning it any number or any text value.

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1") ; Object is created

$oHTTP=0 ; Object is deleted

You don't need to delete Objects when you are finished. If a script exits, AutoIt tries to release all active references to Objects that had been created in the script. Same thing happens when you had defined a local Object variable inside a function, and the function ends with a return.

So my guess is that setting $pObj = 0 is the way to go. I also having seen this and trying to test it futher, tried running this on my own and I saw no recurring increase in memory usage from my system. I have no clue what could have caused this for you, but I'm pretty sure it wasn't my UDF.

[u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output.

Link to comment
Share on other sites

I looked into this a bit further than i had before. I looked to see if there was a way to even close or delete the object but all i found was that the Object variable assigned by the ObjCreate() function is just a pointer to an object not the object itself. And i also found this in the Autoit help file about objects

So my guess is that setting $pObj = 0 is the way to go. I also having seen this and trying to test it futher, tried running this on my own and I saw no recurring increase in memory usage from my system. I have no clue what could have caused this for you, but I'm pretty sure it wasn't my UDF.

Well, what can I say ? It beats me.

Create an object. Load a song. Play the song. Close the object. Repeat. Then put your computer into hibernation.

You'll see that even though you thought you closed the objects, before your system will hibernate, you'll get a number of messages, telling you something about your windows media object(s).

About the memory increase. Compile your script. And monitor the private bytes allocated to the application in realtime. Still, I'll have a carefull second look at my script, but the amount of increase, 1-3 MB for every new song tells me ( I might be wrong ) that this is not something caused by one or two variables declared globally instead of locally or something like that.

Cheers

Link to comment
Share on other sites

About the memory increase. Compile your script. And monitor the private bytes allocated to the application in realtime. Still, I'll have a carefull second look at my script, but the amount of increase, 1-3 MB for every new song tells me ( I might be wrong ) that this is not something caused by one or two variables declared globally instead of locally or something like that.

How do you monitor the private bytes of a program?? Is it the Mem Usage in the Task Manager under the processes tab?

Also, when you play a new song, are you setting the $pObj = 0 Then setting it to $pObj = ObjCreate("WMPlayer.ocx")? This is something you dont need to do. You actually never have to set any of the objects used in this udf to zero, especially the $pObj. I did some tests and found that if you set the $pObj = 0 and reset it to $pObj = ObjCreate("WMPlayer.ocx") at every song change, the Mem Usage keeps goin up and up by about 600 KB for every song. If you dont do this and just keep the link to WMPlayer.ocx open and just change the song being played, then the Mem Usage Levels off after about 3 songs. I'm going to update my Functions and Example to use a WMStartPlayer() and WMClosePlayer() Functions and make it so you won't have to even deal with the Player Object, $pObj. All you will have to deal with is the Song Object, $sObj, which would be like the Track ID in Sound.au3.

Edited by CFire

[u]Scripts and UDF's[/u]WMMedia - UDF full of functions to Control Media Output.

Link to comment
Share on other sites

nice udf, thanks

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

I Updated the File. See Top for Changes. I hope this will fix the Memory issues.

Good idea. This will most probably stop people from doing what I did in the beginning (reseting the player object). Doing so, made my app take over more than 80 MB of memory at some point, and it didn't seem to plan to stop there, which is exactly the opposite of what I was trying to achieve by reseting that. So, I changed my script to do things "the right way", and I did that before posting... but, what I got was increasing memory, :shocked: again...

I now only create a... $pObj once and reuse the object but, the private bytes allocated for the application are still increasing on every "songload".

...and I got fed up a bit. Maybe that's why I didn't notice that this time it wouldn't go beyond 11.9 MB anymore. It gets stuck around 11.5 MB. :( Thanks for mentioning that things leveled off in your experiments.

How do you monitor the private bytes of a program?? Is it the Mem Usage in the Task Manager under the processes tab?

I use

Sysinternal's Process Explorer

, it's free and you can monitor more than memory, graphically with it. Right click your process, properties, performance graph tab. You might notice that those 600 KB are not necessarily 600 KB, cause what I get is very random.

One more thing. What about media with variable bitrate ? Should I just poll WMGetBitrate($sObj) every now and then ?

And how about a WMSetTitle(), WMSetAlbum(), WMSetGenre and so on ?

Oh, and one more thing,

Thanks !

Link to comment
Share on other sites

What do you think about Balance?! :)

Func WMSetBalance($Balance)
    If $pObj <> 0 Then $pObj.settings.Balance = $Balance
    If $pObj = 0 Then SetError(1)
EndFunc

If you gonna put it in your script... Do you wanna put this in it to?:

; ====================================================================================================

; Description ..:   Sets the Balance of the Player.  
; Parameters ...:   $Balance    - New Balance (Total Left: -100  to  100: Total Right)
; Return values :   
; Author .......:   Kip
; Notes ........:   Does Not Affect System/Wave Volumes!!
;                   Sets @error = 1 When This Function has Been called Before WMStartPlayer()
; ====================================================================================================

I will try to get more functions.

Kip

Edited by kip
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...