[vlc-devel] [PATCH 1/1] ActiveX: MRL property now can be used at any time (setting new value will replace playlist content on next "play")
Sergey Radionov
rsatom at gmail.com
Mon Aug 1 15:28:52 CEST 2011
---
projects/activex/plugin.cpp | 122 +++++++++++++++++++++++--------------------
projects/activex/plugin.h | 8 +++
2 files changed, 74 insertions(+), 56 deletions(-)
diff --git a/projects/activex/plugin.cpp b/projects/activex/plugin.cpp
index 57ef10b..f602a26 100644
--- a/projects/activex/plugin.cpp
+++ b/projects/activex/plugin.cpp
@@ -227,7 +227,8 @@ VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
_i_midx(-1),
_i_codepage(CP_ACP),
_b_usermode(TRUE),
- _WindowsManager(DllGetModule())
+ _WindowsManager(DllGetModule()),
+ _b_mrl_changed(FALSE)
{
/*
** bump refcount to avoid recursive release from
@@ -431,7 +432,7 @@ HRESULT VLCPlugin::onLoad(void)
if( UrlIsW(base_url, URLIS_URL) )
{
/* copy base URL */
- _bstr_baseurl = SysAllocString(base_url);
+ setBaseURL(base_url);
}
CoTaskMemFree(base_url);
}
@@ -517,51 +518,6 @@ void VLCPlugin::initVLC()
return;
_p_mlist = libvlc_media_list_new(_p_libvlc);
-
- // initial playlist item
- if( SysStringLen(_bstr_mrl) > 0 )
- {
- char *psz_mrl = NULL;
-
- if( SysStringLen(_bstr_baseurl) > 0 )
- {
- /*
- ** if the MRL a relative URL, we should end up with an absolute URL
- */
- LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
- if( NULL != abs_url )
- {
- psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
- CoTaskMemFree(abs_url);
- }
- else
- {
- psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
- }
- }
- else
- {
- /*
- ** baseURL is empty, assume MRL is absolute
- */
- psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
- }
- if( NULL != psz_mrl )
- {
- const char *options[1];
- int i_options = 0;
-
- char timeBuffer[32];
- if( _i_time )
- {
- snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
- options[i_options++] = timeBuffer;
- }
- // add default target to playlist
- playlist_add_extended_untrusted(psz_mrl, i_options, options);
- CoTaskMemFree(psz_mrl);
- }
- }
};
void VLCPlugin::setErrorInfo(REFIID riid, const char *description)
@@ -1211,22 +1167,71 @@ static void handle_pausable_changed_event(const libvlc_event_t* event, void *par
/* */
+bool VLCPlugin::checkMRL()
+{
+ if(_b_mrl_changed){
+ //if new MRL have been set - we need clear existing playlist and add new MRL to it.
+ playlist_clear();
+
+ //following code have been moved here from initVLC()
+ if( SysStringLen(_bstr_mrl) > 0 )
+ {
+ char *psz_mrl = NULL;
+
+ if( SysStringLen(_bstr_baseurl) > 0 )
+ {
+ /*
+ ** if the MRL a relative URL, we should end up with an absolute URL
+ */
+ LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
+ if( NULL != abs_url )
+ {
+ psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
+ CoTaskMemFree(abs_url);
+ }
+ else
+ {
+ psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
+ }
+ }
+ else
+ {
+ /*
+ ** baseURL is empty, assume MRL is absolute
+ */
+ psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
+ }
+ if( NULL != psz_mrl )
+ {
+ const char *options[1];
+ int i_options = 0;
+
+ char timeBuffer[32];
+ if( _i_time )
+ {
+ snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
+ options[i_options++] = timeBuffer;
+ }
+ // add default target to playlist
+ playlist_add_extended_untrusted(psz_mrl, i_options, options);
+ CoTaskMemFree(psz_mrl);
+ }
+ }
+ _b_mrl_changed=FALSE;
+ return true;
+ }
+ return false;
+}
+
bool VLCPlugin::playlist_select( int idx )
{
- //In some cases, libvlc may not have been initialized yet.
- //So check it and initialize if needed (in getVLC())
- libvlc_instance_t* p_libvlc;
- HRESULT hr = getVLC(&p_libvlc);
- if( FAILED(hr) || !p_libvlc)
- return false;
+ checkMRL();//MRL property can be changed, so we need update playlist
if(!_p_mlist)
return false;//playlist does not exist, nothing to play...
libvlc_media_t *p_m = NULL;
- assert(_p_mlist);
-
libvlc_media_list_lock(_p_mlist);
int count = libvlc_media_list_count(_p_mlist);
@@ -1354,8 +1359,13 @@ void VLCPlugin::player_unregister_events()
int VLCPlugin::playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv)
{
+ libvlc_instance_t* p_libvlc;
+ HRESULT hr = getVLC(&p_libvlc);
+ if( FAILED(hr) || !p_libvlc|| !_p_mlist)
+ return -1;
+
int item = -1;
- libvlc_media_t *p_m = libvlc_media_new_location(_p_libvlc,mrl);
+ libvlc_media_t *p_m = libvlc_media_new_location(p_libvlc, mrl);
if( !p_m )
return -1;
diff --git a/projects/activex/plugin.h b/projects/activex/plugin.h
index d7f5cfe..e42e451 100644
--- a/projects/activex/plugin.h
+++ b/projects/activex/plugin.h
@@ -95,6 +95,7 @@ public:
{
SysFreeString(_bstr_mrl);
_bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
+ _b_mrl_changed = TRUE;
setDirty(TRUE);
};
const BSTR getMRL(void) { return _bstr_mrl; };
@@ -144,6 +145,7 @@ public:
{
SysFreeString(_bstr_baseurl);
_bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
+ _b_mrl_changed = TRUE;
setDirty(TRUE);
};
const BSTR getBaseURL(void) { return _bstr_baseurl; };
@@ -305,6 +307,10 @@ public:
}
void playlist_play()
{
+ if(!isPlaying()&&checkMRL()){//update playlist with changed MRL only in "Stop" mode
+ playlist_select(0);
+ }
+
if( _p_mplayer || playlist_select(0) )
libvlc_media_player_play(_p_mplayer);
}
@@ -335,6 +341,7 @@ protected:
private:
void initVLC();
+ bool checkMRL();
bool playlist_select(int i);
void set_player_window();
void player_register_events();
@@ -374,6 +381,7 @@ private:
RECT _posRect;
LPPICTURE _p_pict;
+ BOOL _b_mrl_changed;//needed for correct maintain playlist on change of MRL property
// persistable properties
BSTR _bstr_baseurl;
BSTR _bstr_mrl;
--
1.7.4.msysgit.0
More information about the vlc-devel
mailing list