]> git.sesse.net Git - vlc/blobdiff - bindings/phonon/vlc/vlcmediaobject.cpp
phonon: Follow 2c57cb and remove exceptions in calls.
[vlc] / bindings / phonon / vlc / vlcmediaobject.cpp
index 3c2286fa3932b42971fa292d087957f47051990e..31a39653853a534af07baf0a6c9061da8310d186 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); // ensure that we are stopped
     libvlc_media_player_release(p_vlc_media_player);
 }
 
@@ -85,8 +83,7 @@ void VLCMediaObject::loadMediaInternal(const QString & filename)
     vlcExceptionRaised();
 
     // Set the media that will be used by the media player
-    libvlc_media_player_set_media(p_vlc_media_player, p_vlc_media, vlc_exception);
-    vlcExceptionRaised();
+    libvlc_media_player_set_media(p_vlc_media_player, p_vlc_media);
 
     // No need to keep the media now
 //    libvlc_media_release(p_vlc_media);
@@ -96,10 +93,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 +102,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;
@@ -125,13 +118,12 @@ void VLCMediaObject::setVLCWidgetId()
 {
     // Get our media player to use our window
 #if defined(Q_OS_UNIX)
-    libvlc_media_player_set_xwindow(p_vlc_media_player, i_video_widget_id, vlc_exception);
+    libvlc_media_player_set_xwindow(p_vlc_media_player, i_video_widget_id);
 #elif defined(Q_OS_WIN)
-    libvlc_media_player_set_hwnd(p_vlc_media_player, i_video_widget_id, vlc_exception);
+    libvlc_media_player_set_hwnd(p_vlc_media_player, i_video_widget_id);
 #elif defined(Q_OS_MAC)
-    libvlc_media_player_set_agl(p_vlc_media_player, i_video_widget_id, vlc_exception);
+    libvlc_media_player_set_agl(p_vlc_media_player, i_video_widget_id);
 #endif
-    vlcExceptionRaised();
 }
 
 void VLCMediaObject::playInternal()
@@ -158,8 +150,7 @@ void VLCMediaObject::pause()
 
 void VLCMediaObject::stop()
 {
-    libvlc_media_player_stop(p_vlc_media_player, vlc_exception);
-    vlcExceptionRaised();
+    libvlc_media_player_stop(p_vlc_media_player);
 //    unloadMedia();
 }
 
@@ -172,7 +163,7 @@ void VLCMediaObject::seekInternal(qint64 milliseconds)
 
 QString VLCMediaObject::errorString() const
 {
-    return libvlc_exception_get_message(vlc_exception);
+    return libvlc_errmsg();
 }
 
 bool VLCMediaObject::hasVideo() const
@@ -188,7 +179,7 @@ bool VLCMediaObject::isSeekable() const
 void VLCMediaObject::connectToAllVLCEvents()
 {
     // Get the event manager from which the media player send event
-    p_vlc_media_player_event_manager = libvlc_media_player_event_manager(p_vlc_media_player, vlc_exception);
+    p_vlc_media_player_event_manager = libvlc_media_player_event_manager(p_vlc_media_player);
     libvlc_event_type_t eventsMediaPlayer[] = {
         libvlc_MediaPlayerPlaying,
         libvlc_MediaPlayerPaused,
@@ -198,7 +189,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 +201,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 +353,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 +369,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);