]> 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 3c2286fa3932b42971fa292d087957f47051990e..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;
@@ -172,7 +166,7 @@ void VLCMediaObject::seekInternal(qint64 milliseconds)
 
 QString VLCMediaObject::errorString() const
 {
-    return libvlc_exception_get_message(vlc_exception);
+    return libvlc_errmsg();
 }
 
 bool VLCMediaObject::hasVideo() const
@@ -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);
@@ -210,7 +204,7 @@ void VLCMediaObject::connectToAllVLCEvents()
 
 
     // Get event manager from media descriptor object
-    p_vlc_media_event_manager = libvlc_media_event_manager(p_vlc_media, vlc_exception);
+    p_vlc_media_event_manager = libvlc_media_event_manager(p_vlc_media);
     libvlc_event_type_t eventsMedia[] = {
         libvlc_MediaMetaChanged,
         libvlc_MediaSubItemAdded,
@@ -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;
@@ -379,40 +372,40 @@ void VLCMediaObject::updateMetaData()
     QMultiMap<QString, QString> metaDataMap;
 
     metaDataMap.insert(QLatin1String("ARTIST"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Artist, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Artist)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("ALBUM"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Album, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Album)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("TITLE"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Title, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Title)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("DATE"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Date, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Date)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("GENRE"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Genre, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Genre)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("TRACKNUMBER"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_TrackNumber, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_TrackNumber)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("DESCRIPTION"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Description, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_Description)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("COPYRIGHT"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_TrackNumber, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_TrackNumber)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("URL"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_URL, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_URL)));
     vlcExceptionRaised();
     metaDataMap.insert(QLatin1String("ENCODEDBY"),
-                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_EncodedBy, vlc_exception)));
+                       QString::fromUtf8(libvlc_media_get_meta(p_vlc_media, libvlc_meta_EncodedBy)));
 
     qDebug() << "updateMetaData(): artist:"
-    << libvlc_media_get_meta(p_vlc_media, libvlc_meta_Artist, vlc_exception);
+    << libvlc_media_get_meta(p_vlc_media, libvlc_meta_Artist);
     vlcExceptionRaised();
     qDebug() << "updateMetaData(): title:"
-    << libvlc_media_get_meta(p_vlc_media, libvlc_meta_Title, vlc_exception);
+    << libvlc_media_get_meta(p_vlc_media, libvlc_meta_Title);
     vlcExceptionRaised();
 
     emit metaDataChanged(metaDataMap);