However, if I invoke the script from command line, vlc runs and a video is played to the raspberry pi hdmi port as expected.VLC media player 3.0.20 Vetinari
Command Line Interface initialized. Type `help' for help.
> Shutting down.
I believe even with proper permissions the issue persists, I am not sure why the result for vlc is different when called from the webpage, rather than from commend line.
Details below:
Device is CM4, and its running pi os lite 32
This is the php that calls the command to run the videoPlayer.sh script, which contains the vlc command.
start-player-form.php:
Code: Select all
<?php
include "../includes/console-log.php";
console_log("start-player-form.php connected");
console_log($_POST['videoToPlay']);
console_log($_POST['loopVideo']);
$videoToPlay = substr($_POST['videoToPlay'], strrpos($_POST['videoToPlay'], "\\"));
console_log($videoToPlay);
if ($_POST['videoToPlay'] == "Choose...") {
echo '<div class="alert alert-warning alert-dismissible fade show" role="alert">
No video file is selected.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
} else {
console_log("start-player-form.php function executed");
$startPlayer = escapeshellcmd("sh ../commands/videoPlayer.sh start '" . $videoToPlay . "' '" . $_POST['loopVideo'] . "'");
$startPlayerOutput = shell_exec($startPlayer);
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
' . $startPlayerOutput . '
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
videoPlayer.sh
Code: Select all
#!/bin/bash
echo "Digital Signage Video Player Starting..."
#find vlc
var=$(ps -ef | grep vlc | grep -v grep | awk '{print $2}')
action=$1
fileName=$2
videoLoop=$3
#default path to video upload folder
path="/var/www/html/videos/"
#play video to HDMI, looped
playAndLoop="vlc --loop --fullscreen ${path}${fileName}"
#play video to HDMI, not looped
playAndExit="vlc --play-and-exit --fullscreen ${path}${fileName}"
if [ "$action" = 'start' ]; then
if [ "$videoLoop" = 'true' ]; then
echo "Playing Video, Loop = true"
$playAndLoop
fi
if [ "$videoLoop" = 'false' ]; then
echo "Playing Video, Loop = false"
$playAndExit
fi
fi
if [ "$action" = 'stop' ]; then
echo "Stopping Video"
sudo kill $var
fi
Permissions:VLC media player 3.0.20 Vetinari
Command Line Interface initialized. Type `help' for help.
> Shutting down.
-rwxrwxrwx 1 pi www-data 758 Feb 23 21:35 videoPlayer.sh
-rwxrwxrwx 1 pi www-data 1076 Feb 23 21:35 start-player-form.php
drwxrwxrwx 2 pi www-data 4096 Feb 23 21:07 videos
Some similar unresolved post i found:
https://ubuntuforums.org/showthread.php?t=2170458
I can call videoPlayer.sh from command line with the following command and the result works as expected, but not if called from the php.
sh /var/www/html/commands/videoPlayer.sh start big* false