I've had this question as well and searched through the forum to see that others have had the same question with no response. So here is the code I've managed to put together to solve my problem.
Please note I'm building an app for Mozilla so it's not tested on IE but hopefully someone can get some insight from this code and port it to IE.
All the code does is setInterval on a function which reads the VLC message log looking for a pattern indicating a new item is being played.
Just place this block of code on your web page, external js, etc...
Code: Select all
//VLCPlugin PlaylistListener//
HTMLEmbedElement.prototype.attachPlaylistListener = function( callback, freq )
{
if ( this.type == 'application/x-vlc-plugin' )
{
//force vlc to log info//
this.log.verbosity = 0;
//track what is currently playing
this.currentlyPlaying = '';
//private interval ID
this._playlistListenerID = null;
this._fileLogFilter = new RegExp('^creating access \'([^\']*)\' path=\'([^\']+)\'','i');
var vlc = this;
this.__playlistListenerID = setInterval(function(){
if ( !vlc._vlcUpdating )
{
vlc._vlcUpdating = true;
var i = vlc.log.messages.iterator();
while ( i.hasNext )
{
var m = i.next();
if ( m.name == 'main' && m.type == 'input' && vlc._fileLogFilter.test(m.message) )
{
var uri = (RegExp.$1!=''?RegExp.$1+'://':'') + RegExp.$2;
if ( vlc.currentlyPlaying != uri )
{
if ( callback && typeof(callback) == 'function' )
{
callback.apply(vlc, ['CHANGE', {to:uri,from:vlc.currentlyPlaying} ]);
}
vlc.currentlyPlaying = uri;
}
}
}
vlc.log.messages.clear();
vlc._vlcUpdating = false;
}
}, freq || 100);
}
};
HTMLEmbedElement.prototype.detachPlaylistListener= function()
{
if ( this._playlistListenerID )
{
clearInterval(this._intervalID);
}
};
Again, this most likely will only work on Firefox but it's a start.
Usage:
Code: Select all
<embed type="application/x-vlc-plugin"
id="vlcviewer" pluginspage="http://www.videolan.org"
version="VideoLAN.VLCPlugin.2" name="vlcviewer"
autoplay="yes" loop="no"></embed>
<script type="text/javascript">
var vlc = document.getElementById('vlcviewer');
vlc.playlist.add('D:\\music\\As I Lay Dying\\As I lay Dying - Track 07.mp3');
vlc.playlist.add('D:\\music\\As I Lay Dying\\As I lay Dying - Track 08.mp3');
vlc.playlist.play();
//the passed callback function will be called everytime the playlist changes
vlc.attachPlaylistListener( function( type, info ){
// do something with this data//
// type = type of event, always 'CHANGE'
// info = object with event info. Currently only has info.to and info.from
myelement.value = info.to;
myoldelement.value = info.from;
} );
//additionally, the currently playing item can be checked with currentlyPlaying property
alert(vlc.currentlyPlaying);
</script>