I need it to randomize the playlist each time it starts, which is every morning.
This is the batch file I use for precisely the same job.
- It closes WMP before starting.
- It unmutes the computer if it had previously been muted.
- It sets WMP to random.
- It sets WMP to repeat play.
- It sets the volume I have decided upon using an additional utility, NirCmd.
- It re-opens WMP and plays the playlist. It keeps doing this until I force it to stop by closing WMP.
- It resets random, repeat & volume afterwards - when I close WMP to stop it.
The close, re-open, re-close WMP steps are necessary to allow the random & repeat settings to be set & cleared.
- WMP calls it "shuffle" rather than "random"
You will need to set these variables to match where you have stuck everything:-ProgFilesFolder***
NirCmdFolder
ChosenSongs
You might want to un-remark out the Pause in the last line to help you see it in action.
*** I use the same batch file on both 32 & 64 bit computers and manipulating this variable makes it choose the correct values for them both.
AlarmDaily.bat
Code:
:: Make it easier to see what's going on
prompt $g
:: OS Type identification
:: This allows me to call NirCmd on all computers
If Defined ProgramFiles(x86) Set ProgFilesFolder=%SystemDrive%\Program Files (x86)
If Not Defined ProgramFiles(x86) Set ProgFilesFolder=%SystemDrive%\Program Files
If Defined ProgramFiles(x86) Set NirCmdFolder=C:\Tools\External\NirSoft\NirCmd\x64
If Not Defined ProgramFiles(x86) Set NirCmdFolder=C:\Tools\External\NirSoft\NirCmd\x86
::Unmute volume if muted
:: I might consider returning the original muted setting if I can find out how it can be done but it hardly seems worthwhile since it would only ever have been muted by accident
Call "%NirCmdFolder%\nircmd.exe" mutesysvolume 0
:: Get current volume
Set UseExpresssion=C:\Tools\External\GetAudioVolume\GetAudioVolume.exe
FOR /F %%i IN (' %UseExpresssion% ') Do Set /a AudioVolume=%%I
:: Set volume to 75 percent of 65535
%NirCmdFolder%\nircmd.exe setsysvolume 49151
:: Set WMP to repeat
:: If WMP is open, close it first for the repeat setting to have any effect
Set TestAppl=wmplayer.exe
tasklist | find /i "%TestAppl%" >nul || GoTo NotRunning
taskkill /im wmplayer.exe
:: Wait so that WMP is fully closed before setting up repeating
:: Changed to 2 secs delay because of a couple of failures to re-start WMP
Timeout /t 2
:NotRunning
:: Turn on WMP repeat and shuffle
Reg Add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences /v ModeLoop /t REG_DWORD /d 1 /f
Reg Add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences /v ModeShuffle /t REG_DWORD /d 1 /f
:: Set the chosen playlist
Set ChosenSongs="F:\Music\Playlists\AlarmCall.wpl"
:PlayBack
"%ProgFilesFolder%\Windows Media Player\wmplayer.exe" %ChosenSongs%
:: I only gained control over waiting until WMP was closed when I set up the setting of ProgFilesFolder and ChosenSongs
:: I did not bother finding out which of these steps was the significant one
:: Reset volume to original level
:: Set volume to AudioVolume percent of 65535
Set /a AudioVolume=%AudioVolume%*65535/100
%NirCmdFolder%\nircmd.exe setsysvolume %AudioVolume%
:: Turn off WMP repeat and shuuffle
Reg Add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences /v ModeLoop /t REG_DWORD /d 0 /f
Reg Add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences /v ModeShuffle /t REG_DWORD /d 0 /f
:EndAlarm
::Pause at EndAlarm during testing
I imagine you'll have some questions,
Denis