Commit a2ccb9b4 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Use the same internal libvlc API as vlccontrol2.cpp does.

parent 6a0f2d46
...@@ -123,37 +123,70 @@ STDMETHODIMP VLCControl::put_Visible(VARIANT_BOOL isVisible) ...@@ -123,37 +123,70 @@ STDMETHODIMP VLCControl::put_Visible(VARIANT_BOOL isVisible)
STDMETHODIMP VLCControl::play(void) STDMETHODIMP VLCControl::play(void)
{ {
libvlc_instance_t *p_libvlc; libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
VLC_Play(i_vlc); libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_playlist_play(p_libvlc, -1, 0, NULL, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
_p_instance->fireOnPlayEvent(); _p_instance->fireOnPlayEvent();
return NOERROR;
} }
return result; return result;
}; };
STDMETHODIMP VLCControl::pause(void) STDMETHODIMP VLCControl::pause(void)
{ {
libvlc_instance_t *p_libvlc; libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
VLC_Pause(i_vlc); libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_playlist_pause(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
_p_instance->fireOnPauseEvent(); _p_instance->fireOnPauseEvent();
return NOERROR;
} }
return result; return result;
}; };
STDMETHODIMP VLCControl::stop(void) STDMETHODIMP VLCControl::stop(void)
{ {
libvlc_instance_t *p_libvlc; libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
VLC_Stop(i_vlc); libvlc_exception_t ex;
_p_instance->fireOnStopEvent(); libvlc_exception_init(&ex);
libvlc_playlist_stop(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
return NOERROR;
} }
_p_instance->fireOnStopEvent();
return result; return result;
}; };
...@@ -184,33 +217,60 @@ STDMETHODIMP VLCControl::get_Position(float *position) ...@@ -184,33 +217,60 @@ STDMETHODIMP VLCControl::get_Position(float *position)
{ {
if( NULL == position ) if( NULL == position )
return E_POINTER; return E_POINTER;
*position = 0.0f;
libvlc_instance_t* p_libvlc;
HRESULT result = E_UNEXPECTED; HRESULT result = E_UNEXPECTED;
if( _p_instance->isRunning() ) result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{ {
libvlc_instance_t *p_libvlc; libvlc_exception_t ex;
result = _p_instance->getVLC(&p_libvlc); libvlc_exception_init(&ex);
if( SUCCEEDED(result) )
libvlc_media_player_t *p_md;
p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
if( !libvlc_exception_raised(&ex) )
{ {
*position = VLC_PositionGet(i_vlc); *position = libvlc_media_player_get_position(p_md, &ex);
return NOERROR; libvlc_media_player_release(p_md);
if( ! libvlc_exception_raised(&ex) )
{
return NOERROR;
}
} }
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
} }
*position = 0.0f;
return result; return result;
}; };
STDMETHODIMP VLCControl::put_Position(float position) STDMETHODIMP VLCControl::put_Position(float position)
{ {
HRESULT result = E_UNEXPECTED; HRESULT result = E_UNEXPECTED;
if( _p_instance->isRunning() ) libvlc_instance_t* p_libvlc;
result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{ {
libvlc_instance_t *p_libvlc; libvlc_exception_t ex;
result = _p_instance->getVLC(&p_libvlc); libvlc_exception_init(&ex);
if( SUCCEEDED(result) )
libvlc_media_player_t *p_md;
p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
if( ! libvlc_exception_raised(&ex) )
{ {
VLC_PositionSet(i_vlc, position); libvlc_media_player_set_position(p_md, position, &ex);
libvlc_media_player_release(p_md);
if( ! libvlc_exception_raised(&ex) )
{
return NOERROR;
}
} }
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
} }
return result; return result;
}; };
...@@ -220,42 +280,68 @@ STDMETHODIMP VLCControl::get_Time(int *seconds) ...@@ -220,42 +280,68 @@ STDMETHODIMP VLCControl::get_Time(int *seconds)
if( NULL == seconds ) if( NULL == seconds )
return E_POINTER; return E_POINTER;
HRESULT result = NOERROR; *seconds = 0;
if( _p_instance->isRunning() ) libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{ {
libvlc_instance_t *p_libvlc; libvlc_exception_t ex;
result = _p_instance->getVLC(&p_libvlc); libvlc_exception_init(&ex);
if( SUCCEEDED(result) )
libvlc_media_player_t *p_md;
p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
if( ! libvlc_exception_raised(&ex) )
{ {
*seconds = VLC_TimeGet(i_vlc); *seconds = libvlc_media_player_get_time(p_md, &ex);
libvlc_media_player_release(p_md);
if( ! libvlc_exception_raised(&ex) )
{
return NOERROR;
}
} }
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
} }
else
*seconds = _p_instance->getTime();
return result; return result;
}; };
STDMETHODIMP VLCControl::put_Time(int seconds) STDMETHODIMP VLCControl::put_Time(int seconds)
{ {
/* setTime function of the plugin sets the time. */
_p_instance->setTime(seconds); _p_instance->setTime(seconds);
return NOERROR; return NOERROR;
}; };
STDMETHODIMP VLCControl::shuttle(int seconds) STDMETHODIMP VLCControl::shuttle(int seconds)
{ {
HRESULT result = E_UNEXPECTED; libvlc_instance_t* p_libvlc;
if( _p_instance->isRunning() ) HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{ {
libvlc_instance_t *p_libvlc; libvlc_exception_t ex;
result = _p_instance->getVLC(&p_libvlc); libvlc_exception_init(&ex);
if( SUCCEEDED(result) )
libvlc_media_player_t *p_md;
p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
if( ! libvlc_exception_raised(&ex) )
{ {
VLC_TimeSet(i_vlc, seconds, true); if( seconds < 0 ) seconds = 0;
libvlc_media_player_set_time(p_md, (int64_t)seconds, &ex);
libvlc_media_player_release(p_md);
if( ! libvlc_exception_raised(&ex) )
{
return NOERROR;
}
} }
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
} }
return result; return result;
}; };
STDMETHODIMP VLCControl::fullscreen(void) STDMETHODIMP VLCControl::fullscreen(void)
...@@ -286,20 +372,33 @@ STDMETHODIMP VLCControl::get_Length(int *seconds) ...@@ -286,20 +372,33 @@ STDMETHODIMP VLCControl::get_Length(int *seconds)
{ {
if( NULL == seconds ) if( NULL == seconds )
return E_POINTER; return E_POINTER;
*seconds = 0;
HRESULT result = NOERROR; libvlc_instance_t* p_libvlc;
if( _p_instance->isRunning() ) HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) )
{ {
libvlc_instance_t *p_libvlc; libvlc_exception_t ex;
result = _p_instance->getVLC(&p_libvlc); libvlc_exception_init(&ex);
if( SUCCEEDED(result) )
libvlc_media_player_t *p_md;
p_md = libvlc_playlist_get_media_player(p_libvlc, &ex);
if( ! libvlc_exception_raised(&ex) )
{ {
*seconds = VLC_LengthGet(i_vlc); *seconds = (double)libvlc_media_player_get_length(p_md, &ex);
return NOERROR; libvlc_media_player_release(p_md);
if( ! libvlc_exception_raised(&ex) )
{
return NOERROR;
}
} }
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
} }
*seconds = 0;
return result; return result;
}; };
STDMETHODIMP VLCControl::playFaster(void) STDMETHODIMP VLCControl::playFaster(void)
...@@ -349,11 +448,22 @@ STDMETHODIMP VLCControl::put_Volume(int volume) ...@@ -349,11 +448,22 @@ STDMETHODIMP VLCControl::put_Volume(int volume)
STDMETHODIMP VLCControl::toggleMute(void) STDMETHODIMP VLCControl::toggleMute(void)
{ {
libvlc_instance_t *p_libvlc; libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
VLC_VolumeMute(i_vlc); libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_audio_toggle_mute(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
return NOERROR;
} }
return result; return result;
}; };
...@@ -364,7 +474,7 @@ STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value) ...@@ -364,7 +474,7 @@ STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
return E_INVALIDARG; return E_INVALIDARG;
libvlc_instance_t *p_libvlc; libvlc_instance_t *p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT hr = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(hr) ) if( SUCCEEDED(hr) )
{ {
int codePage = _p_instance->getCodePage(); int codePage = _p_instance->getCodePage();
...@@ -916,24 +1026,47 @@ STDMETHODIMP VLCControl::get_PlaylistIndex(int *index) ...@@ -916,24 +1026,47 @@ STDMETHODIMP VLCControl::get_PlaylistIndex(int *index)
STDMETHODIMP VLCControl::get_PlaylistCount(int *count) STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
{ {
libvlc_instance_t *p_libvlc; if( NULL == count )
return E_POINTER;
*count = 0;
libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
*count = VLC_PlaylistNumberOfItems(i_vlc); libvlc_exception_t ex;
libvlc_exception_init(&ex);
*count = libvlc_playlist_items_count(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
return NOERROR; return NOERROR;
} }
*count = 0;
return result; return result;
}; };
STDMETHODIMP VLCControl::playlistNext(void) STDMETHODIMP VLCControl::playlistNext(void)
{ {
libvlc_instance_t *p_libvlc; libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
VLC_PlaylistNext(i_vlc); libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_playlist_next(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
return NOERROR; return NOERROR;
} }
return result; return result;
...@@ -941,11 +1074,21 @@ STDMETHODIMP VLCControl::playlistNext(void) ...@@ -941,11 +1074,21 @@ STDMETHODIMP VLCControl::playlistNext(void)
STDMETHODIMP VLCControl::playlistPrev(void) STDMETHODIMP VLCControl::playlistPrev(void)
{ {
libvlc_instance_t *p_libvlc; libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
VLC_PlaylistPrev(i_vlc); libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_playlist_prev(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
return NOERROR; return NOERROR;
} }
return result; return result;
...@@ -953,11 +1096,21 @@ STDMETHODIMP VLCControl::playlistPrev(void) ...@@ -953,11 +1096,21 @@ STDMETHODIMP VLCControl::playlistPrev(void)
STDMETHODIMP VLCControl::playlistClear(void) STDMETHODIMP VLCControl::playlistClear(void)
{ {
libvlc_instance_t *p_libvlc; libvlc_instance_t* p_libvlc;
HRESULT result = _p_instance->getVLC(&p_libvlc); HRESULT result = _p_instance->getVLC(&p_libvlc);
if( SUCCEEDED(result) ) if( SUCCEEDED(result) )
{ {
VLC_PlaylistClear(i_vlc); libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_playlist_clear(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
_p_instance->setErrorInfo(IID_IVLCControl,
libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return E_FAIL;
}
return NOERROR; return NOERROR;
} }
return result; return result;
...@@ -972,8 +1125,7 @@ STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version) ...@@ -972,8 +1125,7 @@ STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version)
if( NULL != versionStr ) if( NULL != versionStr )
{ {
*version = BSTRFromCStr(CP_UTF8, versionStr); *version = BSTRFromCStr(CP_UTF8, versionStr);
return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
return NULL == *version ? E_OUTOFMEMORY : NOERROR;
} }
*version = NULL; *version = NULL;
return E_FAIL; return E_FAIL;
......
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