INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Command line: add file to playing now etc  (Read 3874 times)

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Command line: add file to playing now etc
« on: January 30, 2015, 07:13:31 am »

I've got a Windows batch that opens a specific webpage every hour. I want a simple sound ("C:\Windows\Media\chimes.wav") to be played just after that page opens.
However: I'm playing music all day long with MC.
So this is what has to be done:
- add "C:\Windows\Media\chimes.wav" to "Playing now"
- play that tune
- skip to next song of the original "Playing now"

Is this possible and, if yes: how should this be done?

Thanks for your help!
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

ssands

  • Galactic Citizen
  • ****
  • Posts: 457
Re: Command line: add file to playing now etc
« Reply #1 on: January 30, 2015, 04:12:07 pm »

Would the non-exclusive option work? (http://wiki.jriver.com/index.php/Exclusive_Access) Then your batch file could also launch the chime and MC would just continue.
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #2 on: January 30, 2015, 06:37:57 pm »

I need answers to two questions:

* Do you need to play the sound on the same sound device that MC is using for playback?  (If no, and you have an alternate sound output, and you don't care if playback continues through the chime sound, then this is easier.)

* Only if answer #1 is yes: Do you need MC to play the sound for some reason (due to volume settings or fancy DSP or something) or is it okay if the script itself plays the chime?

If the answer to both is yes, it will be difficult (without disabling exclusive access), and will probably require some more advanced scripting.

If either answer is no, then it is easy and I can write the script for you.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #3 on: January 30, 2015, 06:47:47 pm »

Actually, I thought of a way to do it even if both answers are yes.  You'd have to make a second "chime zone" but you can do it.

It'd be easier for question two's answer to be no, though.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Command line: add file to playing now etc
« Reply #4 on: February 01, 2015, 02:35:23 pm »

I need answers to two questions:

* Do you need to play the sound on the same sound device that MC is using for playback?  (If no, and you have an alternate sound output, and you don't care if playback continues through the chime sound, then this is easier.)
Yes, because I only have one sound device

* Only if answer #1 is yes: Do you need MC to play the sound for some reason (due to volume settings or fancy DSP or something) or is it okay if the script itself plays the chime?
Yes, MC has to play it. I have MC all day long on, playing music. For that reason (in my opinion) another program is not able to take over the sound channel or play simultaneously with the music to the same output

If the answer to both is yes, it will be difficult (without disabling exclusive access), and will probably require some more advanced scripting.

If either answer is no, then it is easy and I can write the script for you.

Thanks for your time and input!
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #5 on: February 01, 2015, 11:20:59 pm »

Yes, MC has to play it. I have MC all day long on, playing music. For that reason (in my opinion) another program is not able to take over the sound channel or play simultaneously with the music to the same output

Irrelevant.  Because Exclusive Access is enabled (and it is better to have it enabled, all around), you must stop playback in MC on that device to allow the same sound output to be used for the chime.

There's no other way, other than to disable Exclusive Access.  So, your choices are:

* Stop playback, play the chime, then resume playback with the next track.
* Add the chime.wav sound to the MC playlist as the next track to play (preserving the existing list), and advance to it.

Since the second option isn't easy to do with MC's command line options (so you'd have to resort to a script using MCWS or COM), I can easily write you one that does the first.

But not tonight.  I'm tired.  Bump this thread again tomorrow if I haven't already responded.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Command line: add file to playing now etc
« Reply #6 on: February 02, 2015, 11:45:03 am »

Well, the second option actually will do exactly what I want it to do. So if you'd be so kind to show me the script, I'd be very much obliged!
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #7 on: February 02, 2015, 01:06:42 pm »

Well, the second option actually will do exactly what I want it to do. So if you'd be so kind to show me the script, I'd be very much obliged!

That's very challenging and would take a LOT of effort.  So, sorry, no.  You're on your own if you insist.

I can write the other one, which will work equally well.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

ssands

  • Galactic Citizen
  • ****
  • Posts: 457
Re: Command line: add file to playing now etc
« Reply #8 on: February 02, 2015, 04:47:05 pm »

How's this for an off-the-wall option:
Buy a Raspberry Pi ($35). Set it up with a speaker (<$10).
Once you've successfully opened your web page, you can send it a command to beep or play a tone. It could either be connected by USB or ethernet.
...and that way you are not mucking around with MC (just letting it play music as you want).

....although perhaps un-clicking exclusive mode is far simpler...
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #9 on: February 02, 2015, 05:04:42 pm »

MC-Play_Sound_Resume.wsf

Code: [Select]
<package>
   <job id="vbs">
      <script language="VBScript">
          Option Explicit

          dim WshShell
          'Create our handy dandy Shell object
          set WshShell = WScript.CreateObject("WScript.Shell")
         
          'Stop playback in MC
          WshShell.Run "MC20.exe /Stop"
         
          WScript.Sleep 300

          'Create the WMPlayer Object
          dim wmPlayer
          set wmPlayer = CreateObject("WMPlayer.ocx")
          'Play audio
          wmPlayer.URL = "C:\Windows\Media\chimes.wav"
          wmPlayer.controls.play
          While wmPlayer.playState <> 1 ' 1 == stopped
            WScript.Sleep 100
          Wend

          'Close the audio file
          wmPlayer.close

          'Restart MC with the next track
          WshShell.Run "MC20.exe /Next"
          WScript.Sleep 100
          WshShell.Run "MC20.exe /Play"
      </script>
   </job>
</package>

Download: http://glynor.com/files/jriver/MC-Play_Sound_Resume.zip
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #10 on: February 02, 2015, 05:08:56 pm »

That should work just fine.  But, if you'd prefer to play the chime sound through MC itself (maybe for volume level reasons), the easiest method will be to:

* Import Chimes.wav into MC
* Make a second zone in MC for chime Playing (this will prevent the current Playing Now list from getting messed up).
* Instead of playing the chimes directly in the script, you'd play it in MC on this alternate zone
* After the chimes.wav has played, then switch back to the regular zone and resume, just like this one does.

However, that won't be quite as reliable because there's no easy way to tell when MC is done playing the file (which I can do with the wmPlayer control).  So, you'll just have to sleep the script for 1200 ms.  If you ever change the Chimes.wav out for a different length file, you'd have to modify the script, and I think it'll be a bit more fragile.

So, if you can use the one I posted above, that would probably be a better choice.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Command line: add file to playing now etc
« Reply #11 on: February 03, 2015, 03:14:27 am »

I was quite stupid in my answer: I meant the SECOND option would do what I wanted. So your solution is just fine.
I downloaded your wsf, but I'm not sure how to get it working.
I've written a small batch-file which opens a website. After that line I put a timer (TIMEOUT 3600, which is an hour) and your script should be started at that stage. Can I 'call' it in my batch or do I have to make a conversion/transformation before I can use it?

Thanks for your help so far!
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #12 on: February 03, 2015, 05:34:25 pm »

The application that calls wsf files (and vbscript files too) is either cscript.exe or wscript.exe.  The only difference between these two choices is that wscript.exe will show "windowed" controls if the script has anything to show, and cscript.exe shows a normal black cmd window (like a BAT file does).  In this case, since my script doesn't show anything, it doesn't matter what you choose generally.  I'd use wscript.exe so you don't get an extra, blank, black cmd window.

So, add this line into your BAT file where you want my script to run:

Code: [Select]
wscript.exe MC-Play_Sound_Resume.wsf
If you need the BAT file to continue asynchronously before the WSF script completes, then you can use this instead:

Code: [Select]
start "" cmd /c wscript.exe MC-Play_Sound_Resume.wsf
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Command line: add file to playing now etc
« Reply #13 on: February 03, 2015, 05:42:44 pm »

If instead, you just want to include the thing you did in your bat file in my script, it uses lines like this to do the same thing as the BAT file:

Code: [Select]
WshShell.Run "MC20.exe /Stop"
So, if you wanted to open (for example), your web browser to Google using your default web browser, you could add:

Code: [Select]
WshShell.Run "http://google.com"
The script's version of the sleep command is WScript.Sleep <MS TO SLEEP>

So, if you wanted to open Google, and then sleep for 3600000 ms (1 hour), before anything else?  You'd modify the script as follows:

Code: [Select]
<package>
   <job id="vbs">
      <script language="VBScript">
          Option Explicit

          dim WshShell
          'Create our handy dandy Shell object
          set WshShell = WScript.CreateObject("WScript.Shell")
          
 'Open Google
 WshShell.Run "http://google.com/"
 
 'Chill out for an hour
 WScript.Sleep 3600000
 
          'Stop playback in MC
          WshShell.Run "MC20.exe /Stop"
          
          WScript.Sleep 300

          'Create the WMPlayer Object
          dim wmPlayer
          set wmPlayer = CreateObject("WMPlayer.ocx")
          'Play audio
          wmPlayer.URL = "C:\Windows\Media\chimes.wav"
          wmPlayer.controls.play
          While wmPlayer.playState <> 1 ' 1 == stopped
            WScript.Sleep 100
          Wend

          'Close the audio file
          wmPlayer.close

          'Restart MC with the next track
          WshShell.Run "MC20.exe /Next"
          WScript.Sleep 100
          WshShell.Run "MC20.exe /Play"
      </script>
   </job>
</package>

Doing it all from within a WSF script has the benefit that it can run completely hidden and doesn't show the black CMD window at all, like a BAT file does.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

MarkCoutinho

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 676
Re: Command line: add file to playing now etc
« Reply #14 on: February 04, 2015, 01:49:50 am »

You're great! Thanks! It works like a chime, ehhh... charm!
Only thing I have to do now is to find a not-annoying sound that's louder than this chimes.wav, because when that's played I can hardly hear it :-) (not even after I've optimized it in Media Editor).
Thanks again for your wonderful help.
Logged
Mark Coutinho
Dutch Top 40 collector of lyrics, sleeves and bios
Pages: [1]   Go Up