import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
-import com.sun.jna.Native;
-
public class JVLC
{
private final LibVlc libvlc = LibVlc.SYNC_INSTANCE;
- private MediaList mediaList;
+ private VLM vlm;
+
+ private Audio audio;
+
+ private volatile boolean released;
+
+ private Canvas canvas;
public JVLC()
{
- String[] args = new String[1];
- args[0] = "jvlc";
- instance = createInstance(args);
- mediaList = new MediaList(this);
+ this(new String[] {});
}
public JVLC(String[] args)
{
- String[] myargs = new String[args.length + 1];
- myargs[0] = "jvlc";
- System.arraycopy(args, 0, myargs, 1, args.length);
- instance = createInstance(myargs);
+ instance = createInstance(args);
+ audio = new Audio(this);
}
public JVLC(String args)
this(args.split(" "));
}
- public MediaInstance play(String media)
+ /*
+ * Core methods
+ */
+ private LibVlcInstance createInstance(String[] args)
+ {
+ libvlc_exception_t exception = new libvlc_exception_t();
+ return libvlc.libvlc_new(args.length, args, exception);
+ }
+
+ public MediaPlayer play(String media)
{
MediaDescriptor mediaDescriptor = new MediaDescriptor(this, media);
- MediaInstance mediaInstance = new MediaInstance(mediaDescriptor);
- mediaInstance.play();
- return mediaInstance;
+ MediaPlayer mediaPlayer = new MediaPlayer(mediaDescriptor);
+ if (canvas != null)
+ {
+ mediaPlayer.setParent(canvas);
+ }
+ mediaPlayer.play();
+ mediaDescriptor.release();
+ return mediaPlayer;
}
public void setVideoOutput(Canvas canvas)
{
- long drawable = Native.getComponentID(canvas);
- libvlc_exception_t exception = new libvlc_exception_t();
- libvlc.libvlc_video_set_parent(instance, drawable, exception );
+ this.canvas = canvas;
}
- /*
- * Core methods
- */
- private LibVlcInstance createInstance(String[] args)
+ public Logger getLogger()
{
- libvlc_exception_t exception = new libvlc_exception_t();
- libvlc.libvlc_exception_init(exception);
+ return new Logger(this);
+ }
- return libvlc.libvlc_new(args.length, args, exception);
+ public VLM getVLM()
+ {
+ if (vlm != null)
+ {
+ vlm.release();
+ }
+ this.vlm = new VLM(this);
+ return vlm;
+ }
+
+ public LoggerVerbosityLevel getLogVerbosity()
+ {
+ int level = libvlc.libvlc_get_log_verbosity(instance);
+ return LoggerVerbosityLevel.getSeverity(level);
+ }
+
+ public void setLogVerbosity(LoggerVerbosityLevel level)
+ {
+ libvlc.libvlc_set_log_verbosity(instance, level.ordinal());
}
+
/**
* Returns the _instance.
* @return the _instance
{
return libvlc;
}
+
+ /**
+ * Releases this instance and the native resources.
+ */
+ public void release()
+ {
+ if (released)
+ {
+ return;
+ }
+ released = true;
+ if (vlm != null)
+ {
+ vlm.release();
+ vlm = null;
+ }
+
+ libvlc.libvlc_release(instance);
+ }
/*
* (non-Javadoc)
@Override
protected void finalize() throws Throwable
{
- libvlc.libvlc_release(instance);
+ release();
super.finalize();
}
-
+
/**
- * Returns the mediaList.
- * @return the mediaList
+ * @return
*/
- public MediaList getMediaList()
+ public Audio getAudio()
{
- return mediaList;
+ return audio;
}
}