Author: fejj
Date: 2007-08-24 17:20:31 -0400 (Fri, 24 Aug 2007)
New Revision: 84820

Modified:
   trunk/moon/src/downloader.cpp
   trunk/moon/src/media.cpp
   trunk/moon/src/media.h
Log:
2007-08-24  Jeffrey Stedfast  <[EMAIL PROTECTED]>

        * media.cpp (UpdateProgress): Use the downloader progress value as
        the buffering progress value as well (since we don't yet stream).
        (DownloaderComplete): Call UpdateProgres() here so that we can
        flush the 100% progress value.

        * downloader.cpp (Write): Update the progress first, so that the
        writer callback can query the actual progress (all data read up to
        and /including/ this point in time).
        (NotifyFinished): Set progress to 100% and emit an event.



Modified: trunk/moon/src/downloader.cpp
===================================================================
--- trunk/moon/src/downloader.cpp       2007-08-24 21:03:58 UTC (rev 84819)
+++ trunk/moon/src/downloader.cpp       2007-08-24 21:20:31 UTC (rev 84820)
@@ -260,9 +260,6 @@
 void
 Downloader::Write (guchar *buf, gsize offset, gsize n)
 {
-       if (write)
-               write (buf, offset, n, consumer_closure);
-       
        // Update progress
        total += n;
        double p;
@@ -270,10 +267,12 @@
                p = total / (double) file_size;
        else 
                p = 0;
-
+       
        SetValue (Downloader::DownloadProgressProperty, Value (p));
-
        Emit (DownloadProgressChangedEvent);
+       
+       if (write)
+               write (buf, offset, n, consumer_closure);
 }
 
 void
@@ -281,9 +280,12 @@
 {
        filename = g_strdup (fname);
        
+       SetValue (Downloader::DownloadProgressProperty, Value (100.0));
+       Emit (DownloadProgressChangedEvent);
+       
        // HACK, we should provide the status code
        SetValue (Downloader::StatusProperty, Value (200));
-       Emit (CompletedEvent, (gpointer)fname);
+       Emit (CompletedEvent, (gpointer) fname);
 }
 
 void

Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp    2007-08-24 21:03:58 UTC (rev 84819)
+++ trunk/moon/src/media.cpp    2007-08-24 21:20:31 UTC (rev 84820)
@@ -93,18 +93,19 @@
 DependencyProperty *MediaElement::PositionProperty;
 DependencyProperty *MediaElement::VolumeProperty;
 
-static gboolean
-advance_frame (void *user_data)
+
+bool
+MediaElement::AdvanceFrame ()
 {
-       MediaElement *media = (MediaElement *) user_data;
        int64_t position;
        
-       if (media->mplayer->AdvanceFrame ()) {
-               media->updating = true;
-               if ((position = media->mplayer->Position ()) < 0)
+       if (mplayer->AdvanceFrame ()) {
+               updating = true;
+               if ((position = mplayer->Position ()) < 0)
                        position = 0;
-               media_element_set_position (media, position * 
TIMESPANTICKS_IN_SECOND / 1000);
-               media->updating = false;
+               position *= TIMESPANTICKS_IN_SECOND / 1000;
+               media_element_set_position (this, position);
+               updating = false;
        }
        
        // FIXME: need to disconnect the timeout if the video is complete
@@ -113,6 +114,14 @@
        return true;
 }
 
+static gboolean
+advance_frame (void *user_data)
+{
+       MediaElement *media = (MediaElement *) user_data;
+       
+       return (gboolean) media->AdvanceFrame ();
+}
+
 MediaElement::MediaElement ()
 {
        mplayer = new MediaPlayer ();
@@ -246,6 +255,11 @@
        double progress = downloader->GetValue 
(DownloadProgressProperty)->AsDouble ();
        
        SetValue (MediaElement::DownloadProgressProperty, Value (progress));
+       
+       // Note: until we start streaming media as we download it,
+       // we'll use the downloader progress as the buffering progress
+       // too.
+       SetValue (MediaElement::BufferingProgressProperty, Value (progress));
 }
 
 void 
@@ -281,6 +295,8 @@
        char *filename = downloader_get_response_file (downloader, part_name);
        bool autoplay = media_element_get_auto_play (this);
        
+       UpdateProgress ();
+       
        printf ("video source changed to `%s'\n", filename);
        
        // FIXME: specify which audio stream index the player should use
@@ -357,8 +373,6 @@
        if (downloader->Started () || downloader->Completed ()) {
                if (loaded && downloader->Completed ())
                        DownloaderComplete ();
-               
-               UpdateProgress ();
        } else {
                downloader->SetWriteFunc (data_write, size_notify, this);
                
@@ -506,7 +520,7 @@
        } else if (prop == MediaElement::BalanceProperty) {
                mplayer->SetBalance (media_element_get_balance (this));
        } else if (prop == MediaElement::BufferingProgressProperty) {
-               // read-only property
+               Emit (BufferingProgressChangedEvent);
        } else if (prop == MediaElement::BufferingTimeProperty) {
                if (!updating) {
                        // FIXME: set the buffering time
@@ -526,9 +540,7 @@
                else
                        mplayer->Mute ();
        } else if (prop == MediaElement::MarkersProperty) {
-               if (!updating) {
-                       // FIXME: set the markers
-               }
+               // FIXME: keep refs to these?
        } else if (prop == MediaElement::NaturalDurationProperty) {
                // read-only property
        } else if (prop == MediaElement::NaturalVideoHeightProperty) {
@@ -1235,7 +1247,7 @@
        MediaElement::BalanceProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "Balance", new Value (0.0));
        MediaElement::BufferingProgressProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "BufferingProgress", new Value (0.0));
        MediaElement::BufferingTimeProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "BufferingTime", Type::TIMESPAN);
-       MediaElement::CanPauseProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "CanPause", new Value (true));
+       MediaElement::CanPauseProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "CanPause", new Value (false));
        MediaElement::CanSeekProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "CanSeek", new Value (false));
        MediaElement::CurrentStateProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "CurrentState", Type::STRING);
        MediaElement::DownloadProgressProperty = DependencyObject::Register 
(Type::MEDIAELEMENT, "DownloadProgress", new Value (0.0));

Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h      2007-08-24 21:03:58 UTC (rev 84819)
+++ trunk/moon/src/media.h      2007-08-24 21:20:31 UTC (rev 84820)
@@ -122,6 +122,8 @@
 
 
 class MediaElement : public MediaBase {
+       guint timeout_id;
+       bool updating;
        bool loaded;
        
        virtual void OnLoaded ();
@@ -160,10 +162,8 @@
        static DependencyProperty *PositionProperty;
        static DependencyProperty *VolumeProperty;
        
-       // technically private
+       bool AdvanceFrame ();
        MediaPlayer *mplayer;
-       guint timeout_id;
-       bool updating;
        
        MediaElement ();
        ~MediaElement ();

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to