Skip to main content
Added a PS with appropriate information.
Source Link
HippoMan
  • 795
  • 1
  • 5
  • 13

PS: This script needs to run as root in order for the /system/bin/am force-stop ... command to function properly.

Therefore, assuming this script is stored as /sdcard/runvid.sh, it needs to be run on a rooted device as follows ...

/system/bin/su -c /sdcard/runvid.sh path-to-video-file [ path-to-subtitle-file ]

PS: This script needs to run as root in order for the /system/bin/am force-stop ... command to function properly.

Therefore, assuming this script is stored as /sdcard/runvid.sh, it needs to be run on a rooted device as follows ...

/system/bin/su -c /sdcard/runvid.sh path-to-video-file [ path-to-subtitle-file ]
Source Link
HippoMan
  • 795
  • 1
  • 5
  • 13

I thought of a way to get an Android script to accomplish this:

(1) create an empty "work" directory;

(2) copy the VideoToPlay.mp4 file into that work directory;

(3) copy the *.ssa file into the same directory under the name "VideoToPlay.ssa";

(4) run the "am start" command I posted above, pointing to the VideoToPlay.mp4

This works because as long as there is an .ssa file in the same directory as the video and with the same base name as the video, VLC will apply the subtitles in that .ssa file to the specified video.

Here is my script to accomplish this:

#!/system/bin/sh                                                                                                                                      

workdir=/sdcard/vidwork
amstart=( /system/bin/am start -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -a android.intent.action.VIEW -d )
amstop=( /system/bin/am force-stop org.videolan.vlc )

# If VLC is running, kill it.
"${amstop[@]}" 1>/dev/null 2>&1

[[ $# -lt 1 ]] && {
  echo "                                                                                                                                              
usage: ${0##*/} video-to-play [ subtitle-file ]                                                                                                       
"
  exit 1
}

videopath="${1}"
shift

[[ -r "${videopath}" ]] ||  {
  echo "                                                                                                                                              
Video doesn't exist: ${videopath}                                                                                                                     
"
  exit 1
}

videoname="${videopath##*/}"

case "${videoname}" in
*.mp4|*.mkv)
  ;;
*) 
  echo "                                                                                                                                              
Video must be mp4 or mkv                                                                                                                              
"
  exit 1
  ;;
esac
  
videobasename="$( echo "${videoname}" | /system/bin/sed -e 's/\.mp4$//i' -e 's/\.mkv$//i' )"

/system/bin/rm -rf "${workdir}" 1>/dev/null 2>&1
/system/bin/mkdir -p "${workdir}" 1>/dev/null 2>&1
    
[[ $# -gt 0 ]] && {
  subpath="${1}"
  shift
  [[ -r ${subpath} ]] || {
    echo "                                                                                                                                            
Subtitle file doesn't exist: ${subpath}                                                                                                               
"
    exit 1
  }
  /bin/cp "${subpath}" "${workdir}/${videobasename}.ssa"
}

/bin/cp "${videopath}" "${workdir}"

cmd=( "${amstart[@]}" "file:///${workdir}/${videoname}" )

{
  "${cmd[@]}"
} 1>/dev/null 2>&1

exit 0