Sign in to follow this  
Followers 0
ajit

Remember last volume

8 posts in this topic

#1 ·  Posted (edited)

Hi,

I am using windows media player object for my audio player.

I need my player to remember the last set volume on the player if possible.

I can use an INI file to store the last audio volume but i do not know how to get the current volume to store it on exiting the window.

Any help would be appreciated.

Regards Ajit

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


;*** Build GUI:
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\WinSpr\AutoIt\_Eigenes\COMStati.kxf
$Form1 = GUICreate("Media Player", 600, 400, -1, -1, $WS_SYSMENU)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$File_Path = GUICtrlCreateInput("", 10, 100, 300)
$Browse_Btn = GUICtrlCreateButton("...", 315, 100, 20, 20)
GUIctrlSetOnEvent($Browse_Btn, "browse")

Global $oRP
$oRP = ObjCreate("MediaPlayer.MediaPlayer.1")
If Not IsObj($oRP) Then
MsgBox(48, "ERROR...", "object failed")
Exit
EndIf

$GUIActiveX = GUICtrlCreateObj($oRP, 10, -220, 280, 285)
$oRPEvt = ObjEvent($oRP, "MediaPlayer_")


With $oRP; Object tag pool
.Rate = 10
.AutoStart = False
.playcount = 0; 0,1,2,3
.displaysize = True
.windowlessVideo = True
.showControls = True
.EnableContextMenu = True
.ShowPositionControls = True
;~ .ShowStatusBar = True
.ShowTracker = True
.EnableTracker = True
.showaudiocontrols = True
.EnablePositionControls = True
.Enabled = True
.ShowDisplay = False
.ShowGotoBar = False
.Mute = False
.Filename = ""
;~ .play ;.Play; .stop .pause
ConsoleWrite(.openState & @CRLF); 0 Not ready, 6 Playing
ConsoleWrite(.currentPosition)
ConsoleWrite(.duration & @CRLF)
ConsoleWrite(.PlayState & @CRLF); 0 Stopped, 1 Pause, 2 playing
;~ .SendKeyboardEvents = true
.ClickToPlay = False
.AutoRewind = False
.CurrentPosition = 0
;.volume = 0; -10000
;~ .volume = -9000; -10000
;~ .balance = -10000; -10000
;~ .AboutBox
EndWith


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
$oRP.ShowPositionControls = True
Consolewrite($oRP.volume & @CRLF)
Sleep(100)
WEnd


Func Form1Close()
Exit
EndFunc


Func browse()
$var = FileOpenDialog("Select file to play", @DesktopDir& "\", "Images (*.mp3;*.wav)");, 1 + 4 )
GUICtrlSetData($File_Path, $var )
$oRP.Filename = $var
EndFunc
Edited by ajit

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ill show u what i got on mine:

Start of script

$Vol2 = IniRead($iFile, 'Volume', 'Vol', '')
If $Vol2 = '' Then
    $Vol = 100
Else
    $Vol = $Vol2
EndIf
GUICtrlSetData($Slider2, $Vol)

On a continuous loop

;=============================================================================
$Vol2 = IniRead($iFile, 'Volume', 'Vol', 'default')
$Vol = GUICtrlRead($Slider2, 1)
SoundSetWaveVolume($Vol)
GUICtrlSetData($InfoVol, $Vol & '%')
;=============================================================================
If $Vol <> $Vol2 Then
IniWrite($iFile, 'Volume', 'Vol', $Vol)
EndIf
;=============================================================================

get it?

greetz

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

@careca,

Thanks for your reply.

But I don't see any way to write data to an INI file unless I have the current volume of the player to be able to use to write the INI data.

My problem is I cannot obtain the current volume in any readable form.

Thanks and regards

Ajit

Share this post


Link to post
Share on other sites

I guess that is not possible

Share this post


Link to post
Share on other sites

hmmm, and i guess you don't understand the code.

$Vol2 = IniRead($iFile, 'Volume', 'Vol', 'default') ;<<<<< Read the value from the ini file 0-100
$Vol = GUICtrlRead($Slider2, 1) ;<<<<< Read slider position, and retrieve value 0-100
SoundSetWaveVolume($Vol) ;<<<<< Use the previous value to set volume
If $Vol <> $Vol2 Then ;<<<<If vol is different from vol2, means the value written on file is different, from the one on the slider
IniWrite($iFile, 'Volume', 'Vol', $Vol) ;<<<< so we write the correct/updated value
EndIf

Get it?


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

@careca

Thanks for your response.

Would you mind integrating your code into mine.

My problem is I have NO slider (nor do i intend to use one) so question of GUICtrlRead does not arise.

I want to use slider of 'Media Player Object' whose reading i cannot get.

Thanks and regards,

Ajit

Share this post


Link to post
Share on other sites

Hi, im sorry, i don't understand anything about objects, your code here only shows a black box and a fileopen dialog...


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

@careca,

I guess problem with OS. I am on XP Professional, Service Pack 3

Regards

Ajit

Share this post


Link to post
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
Sign in to follow this  
Followers 0