Commit bc91ae25 authored by Filippo Carone's avatar Filippo Carone

MediaInstance renamed to MediaPlayer

parent 0b0379db
......@@ -66,13 +66,13 @@ public class Audio
this.jvlc = jvlc;
}
public int getTrack(MediaInstance mediaInstance)
public int getTrack(MediaPlayer mediaInstance)
{
libvlc_exception_t exception = new libvlc_exception_t();
return jvlc.getLibvlc().libvlc_audio_get_track(mediaInstance.getInstance(), exception);
}
public void setTrack(MediaInstance mediaInstance, int track)
public void setTrack(MediaPlayer mediaInstance, int track)
{
libvlc_exception_t exception = new libvlc_exception_t();
jvlc.getLibvlc().libvlc_audio_set_track(mediaInstance.getInstance(), track, exception);
......
......@@ -76,10 +76,10 @@ public class JVLC
return libvlc.libvlc_new(args.length, args, exception);
}
public MediaInstance play(String media)
public MediaPlayer play(String media)
{
MediaDescriptor mediaDescriptor = new MediaDescriptor(this, media);
MediaInstance mediaInstance = new MediaInstance(mediaDescriptor);
MediaPlayer mediaInstance = new MediaPlayer(mediaDescriptor);
mediaInstance.play();
mediaDescriptor.release();
return mediaInstance;
......
......@@ -69,9 +69,9 @@ public class MediaDescriptor
return libvlc.libvlc_media_get_mrl(instance);
}
public MediaInstance getMediaInstance()
public MediaPlayer getMediaInstance()
{
return new MediaInstance(this);
return new MediaPlayer(this);
}
/**
......
......@@ -160,7 +160,7 @@ public class MediaListPlayer
}
}
public void setMediaInstance(MediaInstance mediaInstance)
public void setMediaInstance(MediaPlayer mediaInstance)
{
libvlc_exception_t exception = new libvlc_exception_t();
jvlc.getLibvlc().libvlc_media_list_player_set_media_player(instance, mediaInstance.getInstance(), exception);
......
/*****************************************************************************
* MediaInstance.java: VLC Java Bindings Media Instance
*****************************************************************************
* Copyright (C) 1998-2008 the VideoLAN team
*
* Authors: Filippo Carone <filippo@carone.org>
*
*
* $Id $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
package org.videolan.jvlc;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import org.videolan.jvlc.event.MediaInstanceCallback;
import org.videolan.jvlc.event.MediaInstanceListener;
import org.videolan.jvlc.internal.LibVlc;
import org.videolan.jvlc.internal.LibVlcEventType;
import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
public class MediaPlayer
{
private final LibVlcMediaInstance instance;
private final LibVlc libvlc;
private final LibVlcEventManager eventManager;
private List<MediaInstanceCallback> callbacks = new ArrayList<MediaInstanceCallback>();
private MediaDescriptor mediaDescriptor;
MediaPlayer(JVLC jvlc, LibVlcMediaInstance instance)
{
libvlc_exception_t exception = new libvlc_exception_t();
this.instance = instance;
libvlc = jvlc.getLibvlc();
eventManager = libvlc.libvlc_media_player_event_manager(instance, exception);
}
public MediaPlayer(MediaDescriptor mediaDescriptor)
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc = mediaDescriptor.getLibvlc();
instance = libvlc.libvlc_media_player_new_from_media(mediaDescriptor.getInstance(), exception);
eventManager = libvlc.libvlc_media_player_event_manager(instance, exception);
this.mediaDescriptor = mediaDescriptor;
}
public MediaDescriptor getMediaDescriptor()
{
return mediaDescriptor;
}
public void play()
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_media_player_play(instance, exception);
}
public void stop()
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_media_player_stop(instance, exception);
}
public void pause()
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_media_player_pause(instance, exception);
}
public long getLength()
{
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_media_player_get_length(instance, exception);
}
public long getTime()
{
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_media_player_get_time(instance, exception);
}
public void setTime(long time)
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_media_player_set_time(instance, time, exception);
}
public float getPosition()
{
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_media_player_get_position(instance, exception);
}
public void setPosition(float position)
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_media_player_set_position(instance, position, exception);
}
public boolean willPlay()
{
libvlc_exception_t exception = new libvlc_exception_t();
return (libvlc.libvlc_media_player_will_play(instance, exception) == 1);
}
public float getRate()
{
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_media_player_get_rate(instance, exception);
}
public void setRate(float rate)
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_media_player_set_rate(instance, rate, exception);
}
public boolean hasVideoOutput()
{
libvlc_exception_t exception = new libvlc_exception_t();
return (libvlc.libvlc_media_player_has_vout(instance, exception) == 1);
}
public float getFPS()
{
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_media_player_get_fps(instance, exception);
}
public void addListener(final MediaInstanceListener listener)
{
MediaInstanceCallback callback = new MediaInstanceCallback(this, listener);
libvlc_exception_t exception = new libvlc_exception_t();
for (LibVlcEventType event : EnumSet.range(
LibVlcEventType.libvlc_MediaPlayerPlayed,
LibVlcEventType.libvlc_MediaPlayerTimeChanged))
{
libvlc.libvlc_event_attach(eventManager, event.ordinal(), callback, null, exception);
}
callbacks.add(callback);
}
/**
* {@inheritDoc}
*/
@Override
protected void finalize() throws Throwable
{
libvlc_exception_t exception = new libvlc_exception_t();
for (MediaInstanceCallback callback : callbacks)
{
for (LibVlcEventType event : EnumSet.range(
LibVlcEventType.libvlc_MediaPlayerPlayed,
LibVlcEventType.libvlc_MediaPlayerPositionChanged))
{
libvlc.libvlc_event_detach(eventManager, event.ordinal(), callback, null, exception);
}
}
libvlc.libvlc_media_player_release(instance);
super.finalize();
}
/**
* Returns the instance.
* @return the instance
*/
LibVlcMediaInstance getInstance()
{
return instance;
}
}
......@@ -116,11 +116,11 @@ public class Playlist {
libvlc.libvlc_playlist_loop(libvlcInstance, loop? 1 : 0, exception);
}
public MediaInstance getMediaInstance()
public MediaPlayer getMediaInstance()
{
libvlc_exception_t exception = new libvlc_exception_t();
LibVlcMediaInstance mi = libvlc.libvlc_playlist_get_media_player(libvlcInstance, exception);
return new MediaInstance(jvlc, mi);
return new MediaPlayer(jvlc, mi);
}
}
......@@ -49,7 +49,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#destroyVideo()
*/
public void destroyVideo(MediaInstance media)
public void destroyVideo(MediaPlayer media)
{
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_video_destroy(media.getInstance(), exception );
......@@ -59,7 +59,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#getFullscreen()
*/
public boolean getFullscreen(MediaInstance media) {
public boolean getFullscreen(MediaPlayer media) {
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_get_fullscreen(media.getInstance(), exception) == 1 ? true : false;
}
......@@ -67,7 +67,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#getSnapshot(java.lang.String)
*/
public void getSnapshot(MediaInstance media, String filepath, int width, int height) {
public void getSnapshot(MediaPlayer media, String filepath, int width, int height) {
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_video_take_snapshot(media.getInstance(), filepath, width, height, exception);
}
......@@ -75,7 +75,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#getVideoHeight()
*/
public int getHeight(MediaInstance media) {
public int getHeight(MediaPlayer media) {
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_video_get_height(media.getInstance(), exception);
}
......@@ -83,7 +83,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#getVideoWidth()
*/
public int getWidth(MediaInstance media) {
public int getWidth(MediaPlayer media) {
libvlc_exception_t exception = new libvlc_exception_t();
return libvlc.libvlc_video_get_height(media.getInstance(), exception);
}
......@@ -91,7 +91,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#reparentVideo(java.awt.Component)
*/
public void reparent(MediaInstance media, java.awt.Canvas canvas) {
public void reparent(MediaPlayer media, java.awt.Canvas canvas) {
libvlc_exception_t exception = new libvlc_exception_t();
long drawable = com.sun.jna.Native.getComponentID(canvas);
libvlc.libvlc_video_reparent(media.getInstance(), drawable, exception);
......@@ -108,7 +108,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#setFullscreen(boolean)
*/
public void setFullscreen(MediaInstance media, boolean fullscreen) {
public void setFullscreen(MediaPlayer media, boolean fullscreen) {
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_set_fullscreen(media.getInstance(), fullscreen? 1 : 0, exception);
}
......@@ -116,7 +116,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#toggleFullscreen()
*/
public void toggleFullscreen(MediaInstance media) {
public void toggleFullscreen(MediaPlayer media) {
libvlc_exception_t exception = new libvlc_exception_t();
libvlc.libvlc_toggle_fullscreen(media.getInstance(), exception);
}
......@@ -124,7 +124,7 @@ public class Video
/* (non-Javadoc)
* @see org.videolan.jvlc.VideoIntf#getSize()
*/
public Dimension getSize(MediaInstance media) {
public Dimension getSize(MediaPlayer media) {
return new Dimension (getWidth(media), getHeight(media));
}
......
......@@ -25,7 +25,7 @@
package org.videolan.jvlc.event;
import org.videolan.jvlc.MediaInstance;
import org.videolan.jvlc.MediaPlayer;
import org.videolan.jvlc.internal.LibVlc;
import org.videolan.jvlc.internal.LibVlcEventType;
import org.videolan.jvlc.internal.LibVlc.LibVlcCallback;
......@@ -39,9 +39,9 @@ public class MediaInstanceCallback implements LibVlcCallback
{
private MediaInstanceListener listener;
private MediaInstance mediaInstance;
private MediaPlayer mediaInstance;
public MediaInstanceCallback(MediaInstance mediaInstance, MediaInstanceListener listener)
public MediaInstanceCallback(MediaPlayer mediaInstance, MediaInstanceListener listener)
{
this.mediaInstance = mediaInstance;
this.listener = listener;
......
......@@ -25,20 +25,20 @@
package org.videolan.jvlc.event;
import org.videolan.jvlc.MediaInstance;
import org.videolan.jvlc.MediaPlayer;
public interface MediaInstanceListener
{
void played(MediaInstance mediaInstance);
void played(MediaPlayer mediaInstance);
void paused(MediaInstance mediaInstance);
void paused(MediaPlayer mediaInstance);
void endReached(MediaInstance mediaInstance);
void endReached(MediaPlayer mediaInstance);
void timeChanged(MediaInstance mediaInstance, long newTime);
void timeChanged(MediaPlayer mediaInstance, long newTime);
void positionChanged(MediaInstance mediaInstance);
void positionChanged(MediaPlayer mediaInstance);
}
......@@ -3,7 +3,7 @@ package org.videolan.jvlc.example;
import org.videolan.jvlc.Audio;
import org.videolan.jvlc.JVLC;
import org.videolan.jvlc.MediaDescriptor;
import org.videolan.jvlc.MediaInstance;
import org.videolan.jvlc.MediaPlayer;
import org.videolan.jvlc.VLCException;
import org.videolan.jvlc.Video;
import org.videolan.jvlc.event.MediaInstanceListener;
......@@ -31,32 +31,32 @@ public class VLCExample
System.out.println("... done.");
MediaDescriptor mediaDescriptor = new MediaDescriptor(jvlc, "/home/carone/apps/a.avi");
MediaInstance mediaInstance = mediaDescriptor.getMediaInstance();
MediaPlayer mediaInstance = mediaDescriptor.getMediaInstance();
mediaInstance.addListener(new MediaInstanceListener()
{
public void endReached(MediaInstance mediaInstance)
public void endReached(MediaPlayer mediaInstance)
{
System.out.println("Media instance end reached. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
}
public void paused(MediaInstance mediaInstance)
public void paused(MediaPlayer mediaInstance)
{
System.out.println("Media instance paused. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
}
public void played(MediaInstance mediaInstance)
public void played(MediaPlayer mediaInstance)
{
System.out.println("Media instance played. MRL: " + mediaInstance.getMediaDescriptor().getMrl());
}
public void positionChanged(MediaInstance mediaInstance)
public void positionChanged(MediaPlayer mediaInstance)
{
// TODO Auto-generated method stub
}
public void timeChanged(MediaInstance mediaInstance, long newTime)
public void timeChanged(MediaPlayer mediaInstance, long newTime)
{
System.out.println("new time: " + newTime);
}
......
......@@ -46,7 +46,7 @@ public class JVLCTest
public void jvlcPlay()
{
JVLC jvlc = new JVLC();
MediaInstance instance = jvlc.play(mrl);
MediaPlayer instance = jvlc.play(mrl);
Assert.assertNotNull(instance);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment