]> git.sesse.net Git - vlc/blobdiff - bindings/phonon/vlc/vlcmediaobject.cpp
fix crash when switching phonon backends on the fly, remember to stop libvlc media...
[vlc] / bindings / phonon / vlc / vlcmediaobject.cpp
index ca9760fccd52951d542cf8a2208cf45c8654ebb7..4e06f358f8708e836091f861efff34945a87f9ee 100644 (file)
@@ -32,10 +32,6 @@ namespace Phonon
 {
 namespace VLC {
 
-// VLC returns a strange position
-// We have to multiply by VLC_POSITION_RESOLUTION
-static const int vlcPositionResolution = 1000;
-
 VLCMediaObject::VLCMediaObject(QObject * parent)
         : MediaObject(parent), VLCMediaController()
 {
@@ -59,7 +55,9 @@ VLCMediaObject::VLCMediaObject(QObject * parent)
 
 VLCMediaObject::~VLCMediaObject()
 {
-//    unloadMedia();
+    unloadMedia();
+
+    libvlc_media_player_stop(p_vlc_media_player, vlc_exception); // ensure that we are stopped
     libvlc_media_player_release(p_vlc_media_player);
 }
 
@@ -96,10 +94,6 @@ void VLCMediaObject::loadMediaInternal(const QString & filename)
 
     b_play_request_reached = false;
 
-    // Optimization: wait to see if play() is run just after loadMedia()
-    //               100 milliseconds should be fine
-    QTimer::singleShot(100, this, SLOT(loadMediaInternal()));
-
     // Get meta data (artist, title, etc...)
     updateMetaData();
 
@@ -109,10 +103,10 @@ void VLCMediaObject::loadMediaInternal(const QString & filename)
     // so let's send our own events...
     // This will reset the GUI
     clearMediaController();
-}
 
-void VLCMediaObject::loadMediaInternal()
-{
+    // We need to do this, otherwise we never get any events with the real length
+    libvlc_media_get_duration(p_vlc_media, vlc_exception);
+
     if (b_play_request_reached) {
         // The media is playing, no need to load it
         return;
@@ -198,7 +192,7 @@ void VLCMediaObject::connectToAllVLCEvents()
         libvlc_MediaPlayerTimeChanged,
         libvlc_MediaPlayerTitleChanged,
         libvlc_MediaPlayerPositionChanged,
-        libvlc_MediaPlayerSeekableChanged,
+        //libvlc_MediaPlayerSeekableChanged, //FIXME: doesn't work anymore? it asserts
         libvlc_MediaPlayerPausableChanged,
     };
     int i_nbEvents = sizeof(eventsMediaPlayer) / sizeof(*eventsMediaPlayer);
@@ -362,7 +356,6 @@ void VLCMediaObject::libvlc_callback(const libvlc_event_t *p_event, void *p_user
         // Get duration of media descriptor object item
         libvlc_time_t totalTime = libvlc_media_get_duration(p_vlc_mediaObject->p_vlc_media, vlc_exception);
         vlcExceptionRaised();
-        totalTime = totalTime / vlcPositionResolution;
 
         if (totalTime != p_vlc_mediaObject->i_total_time) {
             p_vlc_mediaObject->i_total_time = totalTime;