0

I've been trying to get this code to work right, but I am failing with every tweak. I need this code to open all the MP3 in the specified directory and then play the files one by one.

Here's the code:

set /p music=Enter location of playlist: 
cd %music%
for %%M in (*.mp3) do start "C:\Program Files (x86)\Windows Media Player" /wait "%%M"

The problem is that this opens all the MP3 files in the directory (at once but because of Windows Media Player queue system they open in one process) and it keeps opening them until it reaches the last file and then starts playing the last file. Because the batch process has ended of course and it's not in a loop.

Mofi
  • 46,139
  • 17
  • 80
  • 143
Areeb
  • 366
  • 1
  • 3
  • 16
  • Look into the arguments for media players. Someone correct me if I am wrong but I think it is being implemented in the "Play All" feature of windows explorer while multi selecting music files. You should be able to send all the files to the current playlist at a time. That should solve your issue. Look into the arguments for media players – Rakshith Ravi Nov 26 '15 at 17:00
  • @Mofi No that's not me. – Areeb Nov 27 '15 at 10:03

2 Answers2

1

Just make an .M3U playlist. You might also find it useful to let the user browse for the album folder rather than asking him to type it.

@echo off
setlocal

path %PATH%;"%PROGRAMFILES(x86)%\Windows Media Player"

rem // folder chooser: https://stackoverflow.com/q/15885132/1683264
set "psCommand=powershell -noprofile "(new-object -COM Shell.Application)^
.BrowseForFolder(0,\"Please choose your album folder.\",0,0).self.path""
for /f "delims=" %%I in ('%psCommand%') do set "folder=%%I"

>"%temp%\playlist.m3u" (for /r "%folder%" %%I in (*.mp3 *.m4a *.ogg *.flac) do echo %%~fI)

start "" wmplayer "%temp%\playlist.m3u"
Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101
0

as you have media player try with this:

@if (@X)==(@Y) @end /* JScript comment 
        @echo off 

        rem :: the first argument is the script name as it will be used for proper help message 
        cscript //E:JScript //nologo "%~f0" %* 
        exit /b %errorlevel% 
@if (@X)==(@Y) @end JScript comment */ 

var wmp = new ActiveXObject("WMPlayer.ocx");
wmp.URL = WScript.Arguments.Item(0);
wmp.openPlayer(wmp.URL);

you need to pass the path to the mp3 file.WMPlayer.ocx has a few properties that can be changed probably in a way you will like.

npocmaka
  • 55,367
  • 18
  • 148
  • 187