How to embed VLC playback windows in Gtkdialog!

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

How to embed VLC playback windows in Gtkdialog!

#1 Post by sc0ttman »

You can use the --drawable-xid option in VLC to embed it into other windows...

You just need to give the window ID, which you get using 'xwininfo'.

Here is an example script 'vlc_embed'. It embeds playback of the given into a gtkdialog window:

Code: Select all

#!/bin/bash

# save this code as vlc_embed

gtkdialog -s <<< '<window title="VLC Playback" width-request="640" height-request="480">
<vbox>
<button><action>killall vlc</action><action type="exit">EXIT_NOW</action></button>
</vbox>
</window>' &
sleep 2

OSC_WID="$(xwininfo -name "VLC Playback" | grep -m1 'Window id: ' | cut -f4 -d' ')"

vlc -I dummy --drawable-xid  $OSC_WID "$@" &

exit 0
Usage of the above:

vlc_embed /path/to/file.avi

EDIT: No idea how to send playback control to VLC once its embedded thoough...

If anyone knows how I can send play/stop/next/prev/fullscreen/etc commands to VLC when it's embedded, I will be VERY grateful!
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#2 Post by sc0ttman »

Here is how you add controls:

Essentially, use this option with vlc:

--extraintf rc --rc-host localhost:123

VLC will then listen on localhost:123 for commands...

Then you can send the VLC commands to localhost:123, like so:

echo pause | nc localhost 123

(where 'pause' is any valid VLC playback command)

Here is a simple script, save it as 'vlc_embed', make it exec, and run like so:

./vlc_embed "path/to/file"

Code: Select all

#!/bin/bash

gtkdialog -s <<< '<window title="VLC Controls" width-request="600" height-request="450">
<vbox>
<button><label>Play/Stop</label><action>echo pause | nc localhost 123</action></button>
<button><label>Quit</label><action>echo quit | nc localhost 123</action><action type="exit">EXIT_NOW</action></button>
</vbox>
</window>' &
sleep 1

OSC_WID="$(xwininfo -name "VLC Controls" | grep -m1 'Window id: ' | cut -f4 -d' ')"
echo OSC_WID = $OSC_WID
export OSC_WID
vlc --extraintf rc --rc-host localhost:123 --drawable-xid  $OSC_WID "$@" 
exit 0
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#3 Post by sc0ttman »

Updated: supports playback of files and dirs...

Save the code as a script:

Code: Select all

#!/bin/bash

cd /mnt 
[ "$1" = "" ] && FILE="$(Xdialog --stdout --title 'Choose a file' --fselect /mnt 0 0)" || FILE="$@"

if [ -e "$FILE" ];then

echo 'style "vlc_embed"
{ bg[NORMAL]		= "#000000" 
  fg[NORMAL]        = "#000000" 
  base[NORMAL]      = "#ffffff"  
  text[NORMAL]      = "#ffffff" 
}
class "GtkButton" style "vlc_embed"
class "*" style "vlc_embed"' > /tmp/gtkrc
#export GTK2_RC_FILES=/tmp/gtkrc:/root/.gtkrc-2.0 ## uncomment to change the theme of the gtkdialog window

	if [ -d "$FILE" ];then
		FILE="`find "$FILE" -maxdepth 1`" 
		echo "$FILE" > /tmp/vlc_embed_playlist.m3u
		FILE=/tmp/vlc_embed_playlist.m3u
	fi

	echo "$FILE"
	gtkdialog -s <<< '<window title="VLC Controls" width-request="520" height-request="350">
		<vbox>
			<hbox height-request="28">
				<button><input file stock="gtk-media-previous"></input><label>Prev</label><action>echo prev | nc localhost 12345</action></button>
				<button><input file stock="gtk-media-play"></input><label>Play/Stop</label><action>echo pause | nc localhost 12345</action></button>
				<button><input file stock="gtk-media-next"></input><label>Next</label><action>echo next | nc localhost 12345</action></button>
				<button><input file stock="gtk-fullscreen"></input><label>FS</label><action>echo f | nc localhost 12345</action></button>
				<button><input file stock="gtk-go-up"></input><label>Vol Up</label><action>echo volup 5 | nc localhost 12345</action></button>
				<button><input file stock="gtk-go-down"></input><label>Vol Dwn</label><action>echo voldown 5 | nc localhost 12345</action></button>
				<button><input file stock="gtk-info"></input><label>Info</label><action>echo show_time 5 | nc localhost 12345</action></button>
				<button><input file stock="gtk-quit"></input><label>Quit</label><action>echo quit | nc localhost 12345</action><action type="exit">EXIT_NOW</action></button>
			</hbox>
			<text height-request="280"><label>""</label></text>
			<text><label>"VLC version '$(vlc --version 2>&1| grep '^VLC media player' | cut -f4 -d' ')'"</label></text>
		</vbox>
	</window>' &
	sleep 1

	OSC_WID=''
	export OSC_WID="$(xwininfo -name "VLC Controls" | grep -m1 'Window id: ' | cut -f4 -d' ')"
	[ "$OSC_WID" != '' ] && vlc --vout xcb_xv --extraintf oldrc --rc-host localhost:12345 --drawable-xid  $OSC_WID "$FILE" vlc://quit

else
	Xdialog --msgbox "Not found: $FILE" 0 0
fi
exit 0
Screenshot:

Image
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#4 Post by technosaurus »

some more controls

Code: Select all

add XYZ  . . . . . . . . . . . . add XYZ to playlist
enqueue XYZ  . . . . . . . . . queue XYZ to playlist
playlist . . . . .  show items currently in playlist
play . . . . . . . . . . . . . . . . . . play stream
stop . . . . . . . . . . . . . . . . . . stop stream
next . . . . . . . . . . . . . .  next playlist item
prev . . . . . . . . . . . .  previous playlist item
goto . . . . . . . . . . . . . .  goto item at index
repeat [on|off] . . . .  toggle playlist item repeat
loop [on|off] . . . . . . . . . toggle playlist loop
random [on|off] . . . . . . .  toggle random jumping
clear . . . . . . . . . . . . . . clear the playlist
status . . . . . . . . . . . current playlist status
title [X]  . . . . . . set/get title in current item
title_n  . . . . . . . .  next title in current item
title_p  . . . . . .  previous title in current item
chapter [X]  . . . . set/get chapter in current item
chapter_n  . . . . . .  next chapter in current item
chapter_p  . . . .  previous chapter in current item
seek X . . . seek in seconds, for instance `seek 12'
pause  . . . . . . . . . . . . . . . .  toggle pause
fastforward  . . . . . . . .  .  set to maximum rate
rewind  . . . . . . . . . . . .  set to minimum rate
faster . . . . . . . . . .  faster playing of stream
slower . . . . . . . . . .  slower playing of stream
normal . . . . . . . . . .  normal playing of stream
frame. . . . .  . . . . . . . .  play frame by frame
f [on|off] . . . . . . . . . . . . toggle fullscreen
info . . . . .  information about the current stream
stats  . . . . . . . .  show statistical information
get_time . . seconds elapsed since stream's beginning
is_playing . . . .  1 if a stream plays, 0 otherwise
get_title . . . . .  the title of the current stream
get_length . . . .  the length of the current stream
volume [X] . . . . . . . . . .  set/get audio volume
volup [X]  . . . . . . .  raise audio volume X steps
voldown [X]  . . . . . .  lower audio volume X steps
adev [device]  . . . . . . . .  set/get audio device
achan [X]. . . . . . . . . .  set/get audio channels
atrack [X] . . . . . . . . . . . set/get audio track
vtrack [X] . . . . . . . . . . . set/get video track
vratio [X]  . . . . . . . set/get video aspect ratio
vcrop [X]  . . . . . . . . . . .  set/get video crop
vzoom [X]  . . . . . . . . . . .  set/get video zoom
snapshot . . . . . . . . . . . . take video snapshot
strack [X] . . . . . . . . .  set/get subtitle track
key [hotkey name] . . . . . .  simulate hotkey press
help . . . . . . . . . . . . . . . this help message
logout . . . . . . .  exit (if in socket connection)
quit . . . . . . . . . . . . . . . . . . .  quit vlc
shortcut keys are here:
http://repo.or.cz/w/vlc.git/blob/HEAD:/ ... vlc_keys.h
... but they are hex numbers with no comment as to the corresponding readable keys
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Post Reply