[vlc-devel] commit: libvlc, jvlc: media_player_is_playing method added (Filippo Carone )

git version control git at videolan.org
Tue Jan 6 22:48:18 CET 2009


vlc | branch: master | Filippo Carone <littlejohn at videolan.org> | Tue Jan  6 22:48:03 2009 +0100| [76ca900120e98d094da957bc2eba1c96aeaec047] | committer: Filippo Carone 

libvlc, jvlc: media_player_is_playing method added

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=76ca900120e98d094da957bc2eba1c96aeaec047
---

 .../java/org/videolan/jvlc/MediaListPlayer.java    |    2 +-
 .../main/java/org/videolan/jvlc/MediaPlayer.java   |    6 +++++
 .../java/org/videolan/jvlc/internal/LibVlc.java    |    2 +
 .../jvlc/internal/LibVlcMediaPlayerTest.java       |   12 ++++++++++
 include/vlc/libvlc.h                               |    9 +++++++
 src/control/media_player.c                         |   23 ++++++++++++++++++++
 src/libvlc.sym                                     |    1 +
 7 files changed, 54 insertions(+), 1 deletions(-)

diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java
index 2a073b9..b5e9a72 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaListPlayer.java
@@ -35,7 +35,7 @@ public class MediaListPlayer
     private final LibVlcMediaListPlayer instance;
 
     private final JVLC jvlc;
-
+    
     public MediaListPlayer(JVLC jvlc)
     {
         libvlc_exception_t exception = new libvlc_exception_t();
diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java
index 5377e99..da069b6 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaPlayer.java
@@ -150,6 +150,12 @@ public class MediaPlayer
         libvlc_exception_t exception = new libvlc_exception_t();
         return libvlc.libvlc_media_player_get_fps(instance, exception);
     }
+    
+    public boolean isPlaying()
+    {
+        libvlc_exception_t exception = new libvlc_exception_t();
+        return libvlc.libvlc_media_player_is_playing(instance, exception) == 1? true : false;
+    }
 
     public void addListener(final MediaPlayerListener listener)
     {
diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlc.java b/bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlc.java
index a3c29b2..97aa592 100644
--- a/bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlc.java
+++ b/bindings/java/core/src/main/java/org/videolan/jvlc/internal/LibVlc.java
@@ -454,6 +454,8 @@ public interface LibVlc extends Library
 
     void libvlc_media_player_set_position(LibVlcMediaPlayer instance, float position, libvlc_exception_t exception);
 
+    int libvlc_media_player_is_playing(LibVlcMediaPlayer instance, libvlc_exception_t exception);
+    
     int libvlc_media_player_will_play(LibVlcMediaPlayer instance, libvlc_exception_t exception);
 
     void libvlc_media_player_set_rate(LibVlcMediaPlayer instance, float rate, libvlc_exception_t exception);
diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java
index c96602a..8cda246 100644
--- a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java
+++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java
@@ -59,6 +59,18 @@ public class LibVlcMediaPlayerTest extends AbstractVLCInternalTest
     }
     
     @Test
+    public void mediaPlayerIsPlaying() throws Exception
+    {
+        LibVlcMedia md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
+        LibVlcMediaPlayer mi = libvlc.libvlc_media_player_new_from_media(md, exception);
+        Assert.assertEquals(0, libvlc.libvlc_media_player_is_playing(mi, exception));
+        libvlc.libvlc_media_player_play(mi, exception);
+        Assert.assertEquals(0, exception.raised);
+        Thread.sleep(200);
+        Assert.assertEquals(1, libvlc.libvlc_media_player_is_playing(mi, exception));
+    }
+    
+    @Test
     public void mediaPlayerPauseBad()
     {
         LibVlcMedia md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h
index 182bfca..f2254d7 100644
--- a/include/vlc/libvlc.h
+++ b/include/vlc/libvlc.h
@@ -499,6 +499,15 @@ VLC_PUBLIC_API libvlc_media_t * libvlc_media_player_get_media( libvlc_media_play
 VLC_PUBLIC_API libvlc_event_manager_t * libvlc_media_player_event_manager ( libvlc_media_player_t *, libvlc_exception_t * );
 
 /**
+ * is_playing
+ *
+ * \param p_mi the Media Player
+ * \param p_e an initialized exception pointer
+ * \return 1 if the media player is playing, 0 otherwise
+ */
+VLC_PUBLIC_API int libvlc_media_player_is_playing ( libvlc_media_player_t *, libvlc_exception_t * );
+
+/**
  * Play
  *
  * \param p_mi the Media Player
diff --git a/src/control/media_player.c b/src/control/media_player.c
index 7dbbb0c..87788cc 100644
--- a/src/control/media_player.c
+++ b/src/control/media_player.c
@@ -634,6 +634,29 @@ void libvlc_media_player_pause( libvlc_media_player_t *p_mi,
 }
 
 /**************************************************************************
+ * is_playing
+ **************************************************************************/
+int libvlc_media_player_is_playing( libvlc_media_player_t *p_mi,
+                                     libvlc_exception_t *p_e )
+{
+    input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi, p_e );
+
+    if( !p_input_thread )
+        return 0;
+
+    libvlc_state_t state = libvlc_media_player_get_state( p_mi, p_e );
+
+    vlc_object_release( p_input_thread );
+    
+    if( state == libvlc_Playing )
+    {
+        return 1;
+    }
+    return 0;
+}
+
+
+/**************************************************************************
  * Stop
  **************************************************************************/
 void libvlc_media_player_stop( libvlc_media_player_t *p_mi,
diff --git a/src/libvlc.sym b/src/libvlc.sym
index 3a02295..430ca71 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -134,6 +134,7 @@ libvlc_media_player_get_title
 libvlc_media_player_get_title_count
 libvlc_media_player_has_vout
 libvlc_media_player_is_seekable
+libvlc_media_player_is_playing
 libvlc_media_player_new
 libvlc_media_player_new_from_input_thread
 libvlc_media_player_new_from_media




More information about the vlc-devel mailing list