0

Note: The question regards running a PHP script from a shell, not a browser/server setup.

This article says how to play music from a Python script. Can a PHP script run in a shell play music, for example by starting a background process? (I'm on macOS.)

I'd like to play the mp3 and m4a/alac formats, and once the music plays I want to be able to do pausing, resuming, jumping forwards/backwards by sending signals / calling functions.

$ php script.php

Pseudo-example of script.php:

<?php

for($t=0; $t<5; $t++) {

  $id = play_song("song $t.m4a");
  sleep(5);

  pause_song($id);
  sleep(5);

  resume_song($id);
  sleep(5);

  stop_song($id);
  sleep(5);

}

?>
forthrin
  • 2,709
  • 3
  • 28
  • 50

1 Answers1

1

Use VLC for play music through shell

Squalo
  • 119
  • 11
  • If the script first tells VLC to play a song, how can the script later tell VLC to jump forward 10 seconds, for example? A named pipe? By process ID? – forthrin Apr 23 '18 at 17:49
  • What are you trying to do exactly? Here you can see vlc documentation https://wiki.videolan.org/VLC_command-line_help/ – Squalo Apr 24 '18 at 21:46
  • Specifically, I'd like to play music from a PHP script, and be able to control the player from the script. More generally, I'd like to learn how you can use UNIX tricks to do things from a script language that the language does not support out of the box. You could also say I would like the convenience and comfort of a "high level" script language such as PHP or Python, and still be able to do "low level" things like playing and controlling music or video, without having to write the whole thing in C, because the code is going to do a lot of other things than just play music. – forthrin Apr 25 '18 at 07:01