Basic Audio Player
So far we have created media players that can play audio and video. Here we build a media player for playing audio only. An audio player has no video surface and is a little bit simpler to use than a full-blown audio and video player.
Let's Get Started
You should now already have a basic template for how to create a vlcj application, so this tutorial will no longer duplicate all of the code each time - instead we'll just show the new code fragments.
This tutorial will not have a user interface, it will be a command-line application that plays one audio file and exits.
An audio media player can of course be part of an application with a user interface, but we've seen how to integrate a vlcj media player into such an application already so there's no point repeating it here.
Audio Media Player Component
The first thing to do is to create the audio media player component...
Here we simply create the component - there is no user interface or video surface to think about.
Media player event listeners are exactly the same for audio media players as they are for the media players we've seen already.
In this tutorial we simply exit the application in response to various events.
Playing an Audio File
Playing audio works just the same as playing any other media file...
Here is the finished code, it is very simple:
We assume that the name of the audio file is passed as the first command-line argument.
Of note in this code, but not directly related to vlcj, in the
main method we
join() the current thread - i.e. effectively we wait forever. Without this
the application would exit immediately after the
main method terminates. If
this application had a user interface, then the user interface thread keeps the
application alive even after the main method terminates. This application will
exit when one the media player events we're listening for is raised.
This tutorial has shown how to create a very simple audio player. There is really very little vlcj code in here. This can be used as the foundation to create a full-blown application with a user interface.