[vlc-devel] [PATCH 2/4] Add some useful events to the JS API

Daniel Amm da2424 at t-online.de
Tue Jun 6 17:30:57 CEST 2017


---
 activex/axvlc.idl        | 17 +++++++++++
 activex/plugin.cpp       | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
 activex/plugin.h         | 10 +++++++
 npapi/vlcplugin_base.cpp | 28 ++++++++++++++++++
 4 files changed, 129 insertions(+)

diff --git a/activex/axvlc.idl b/activex/axvlc.idl
index e87a945..12cf596 100644
--- a/activex/axvlc.idl
+++ b/activex/axvlc.idl
@@ -84,6 +84,12 @@ library AXVLC
     const int DISPID_MediaPlayerMediaChangedEvent = 214;
     const int DISPID_MediaPlayerTitleChangedEvent = 215;
     const int DISPID_MediaPlayerLengthChangedEvent = 216;
+    const int DISPID_MediaPlayerChapterChangedEvent = 217;
+
+    const int DISPID_MediaPlayerVoutEvent = 218;
+    const int DISPID_MediaPlayerMutedEvent = 219;
+    const int DISPID_MediaPlayerUnmutedEvent = 220;
+    const int DISPID_MediaPlayerAudioVolumeEvent = 221;
 
     [
       uuid(DF48072F-5EF8-434e-9B40-E2F3AE759B5F),
@@ -129,6 +135,17 @@ library AXVLC
             void MediaPlayerTitleChanged([in] int title);
             [id(DISPID_MediaPlayerLengthChangedEvent), helpstring("Length changed")]
             void MediaPlayerLengthChanged([in] long length);
+            [id(DISPID_MediaPlayerChapterChangedEvent), helpstring("Chapter changed")]
+            void MediaPlayerChapterChanged([in] int chapter);
+
+            [id(DISPID_MediaPlayerVoutEvent), helpstring("Number of vout changed")]
+            void MediaPlayerVout([in] int count);
+            [id(DISPID_MediaPlayerMutedEvent), helpstring("Audio muted")]
+            void MediaPlayerMuted();
+            [id(DISPID_MediaPlayerUnmutedEvent), helpstring("Audio unmuted")]
+            void MediaPlayerUnmuted();
+            [id(DISPID_MediaPlayerAudioVolumeEvent), helpstring("Audio volume changed")]
+            void MediaPlayerAudioVolume([in] float volume);
     };
 
     [
diff --git a/activex/plugin.cpp b/activex/plugin.cpp
index d84cac9..6a0435f 100644
--- a/activex/plugin.cpp
+++ b/activex/plugin.cpp
@@ -1114,6 +1114,61 @@ void VLCPlugin::fireOnMediaPlayerLengthChangedEvent(long length)
     vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerLengthChangedEvent, &params);
 }
 
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+void VLCPlugin::fireOnMediaPlayerChapterChangedEvent(int chapter)
+{
+    DISPPARAMS params;
+    params.cArgs = 1;
+    params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
+    memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
+    params.rgvarg[0].vt = VT_I2;
+    params.rgvarg[0].iVal = chapter;
+    params.rgdispidNamedArgs = NULL;
+    params.cNamedArgs = 0;
+    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerChapterChangedEvent, &params);
+}
+#endif
+
+void VLCPlugin::fireOnMediaPlayerVoutEvent(int count)
+{
+    DISPPARAMS params;
+    params.cArgs = 1;
+    params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
+    memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
+    params.rgvarg[0].vt = VT_I2;
+    params.rgvarg[0].iVal = count;
+    params.rgdispidNamedArgs = NULL;
+    params.cNamedArgs = 0;
+    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerVoutEvent, &params);
+}
+
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 2, 0)
+void VLCPlugin::fireOnMediaPlayerMutedEvent()
+{
+    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
+    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerMutedEvent, &dispparamsNoArgs);
+}
+
+void VLCPlugin::fireOnMediaPlayerUnmutedEvent()
+{
+    DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
+    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerUnmutedEvent, &dispparamsNoArgs);
+}
+
+void VLCPlugin::fireOnMediaPlayerAudioVolumeEvent(float volume)
+{
+    DISPPARAMS params;
+    params.cArgs = 1;
+    params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
+    memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
+    params.rgvarg[0].vt = VT_R4;
+    params.rgvarg[0].fltVal = volume;
+    params.rgdispidNamedArgs = NULL;
+    params.cNamedArgs = 0;
+    vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerAudioVolumeEvent, &params);
+}
+#endif
+
 /* */
 
 void VLCPlugin::set_player_window()
@@ -1178,6 +1233,25 @@ void VLCPlugin::player_register_events()
     em.onLengthChanged( [this]( int64_t length ) {
         fireOnMediaPlayerLengthChangedEvent( length );
     });
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+    em.onChapterChanged( [this]( int chapter ) {
+        fireOnMediaPlayerChapterChangedEvent( chapter );
+    });
+#endif
+    em.onVout( [this]( int count ) {
+        fireOnMediaPlayerVoutEvent( count );
+    });
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 2, 0)
+    em.onMuted( [this] {
+        fireOnMediaPlayerMutedEvent();
+    });
+    em.onUnmuted( [this] {
+        fireOnMediaPlayerUnmutedEvent();
+    });
+    em.onAudioVolume( [this]( float volume ) {
+        fireOnMediaPlayerAudioVolumeEvent( volume );
+    });
+#endif
 }
 
 #undef B
diff --git a/activex/plugin.h b/activex/plugin.h
index d8abd87..de7c9d9 100644
--- a/activex/plugin.h
+++ b/activex/plugin.h
@@ -258,6 +258,16 @@ public:
     void fireOnMediaPlayerMediaChangedEvent();
     void fireOnMediaPlayerTitleChangedEvent(int title);
     void fireOnMediaPlayerLengthChangedEvent(long length);
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+    void fireOnMediaPlayerChapterChangedEvent(int chapter);
+#endif
+
+    void fireOnMediaPlayerVoutEvent(int count);
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 2, 0)
+    void fireOnMediaPlayerMutedEvent();
+    void fireOnMediaPlayerUnmutedEvent();
+    void fireOnMediaPlayerAudioVolumeEvent(float volume);
+#endif
 
     // controlling IUnknown interface
     LPUNKNOWN pUnkOuter;
diff --git a/npapi/vlcplugin_base.cpp b/npapi/vlcplugin_base.cpp
index a1f5a2a..9a3c035 100644
--- a/npapi/vlcplugin_base.cpp
+++ b/npapi/vlcplugin_base.cpp
@@ -373,7 +373,16 @@ static struct vlcevents_t {
     { "MediaPlayerSeekableChanged", libvlc_MediaPlayerSeekableChanged },
     { "MediaPlayerPausableChanged", libvlc_MediaPlayerPausableChanged },
     { "MediaPlayerTitleChanged", libvlc_MediaPlayerTitleChanged },
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+    { "MediaPlayerChapterChanged", libvlc_MediaPlayerChapterChanged },
+#endif
     { "MediaPlayerLengthChanged", libvlc_MediaPlayerLengthChanged },
+    { "MediaPlayerVout", libvlc_MediaPlayerVout },
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 2, 0)
+    { "MediaPlayerMuted", libvlc_MediaPlayerMuted },
+    { "MediaPlayerUnmuted", libvlc_MediaPlayerUnmuted },
+    { "MediaPlayerAudioVolume", libvlc_MediaPlayerAudioVolume },
+#endif
 };
 
 void VlcPluginBase::subscribe(const char* eventName, npapi::Variant listener)
@@ -438,9 +447,28 @@ void VlcPluginBase::subscribe(const char* eventName, npapi::Variant listener)
         case libvlc_MediaPlayerTitleChanged:
             e = player().get_mp().eventManager().onTitleChanged( std::move( closure ) );
             break;
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
+        case libvlc_MediaPlayerChapterChanged:
+            e = player().get_mp().eventManager().onChapterChanged( std::move( closure ) );
+            break;
+#endif
         case libvlc_MediaPlayerLengthChanged:
             e = player().get_mp().eventManager().onLengthChanged( std::move( closure ) );
             break;
+        case libvlc_MediaPlayerVout:
+            e = player().get_mp().eventManager().onVout( std::move( closure ) );
+            break;
+#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 2, 0)
+        case libvlc_MediaPlayerMuted:
+            e = player().get_mp().eventManager().onMuted( std::move( closure ) );
+            break;
+        case libvlc_MediaPlayerUnmuted:
+            e = player().get_mp().eventManager().onUnmuted( std::move( closure ) );
+            break;
+        case libvlc_MediaPlayerAudioVolume:
+            e = player().get_mp().eventManager().onAudioVolume( std::move( closure ) );
+            break;
+#endif
         default:
             break;
     }
-- 
2.11.1.windows.1



More information about the vlc-devel mailing list