Author: fejj
Date: 2007-08-23 16:47:26 -0400 (Thu, 23 Aug 2007)
New Revision: 84752
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/media.cpp
trunk/moon/src/media.h
Log:
2007-08-23 Jeffrey Stedfast <[EMAIL PROTECTED]>
* media.cpp (MediaElement): Initialize 'loaded' to false.
(SetSource): Don't call DownloaderComplete() if we haven't been
loaded yet.
(GetValue): Convert to position from ms to TimeSpan ticks.
(OnLoaded): Set loaded to true and, if we have a downloader which
has completed the download, call DownloaderComplete() which will
then open the media file and autoplay if appropriate.
(OnPropertyChanged): Protect against creating a downloader for an
empty string uri.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-08-23 20:44:49 UTC (rev 84751)
+++ trunk/moon/src/ChangeLog 2007-08-23 20:47:26 UTC (rev 84752)
@@ -1,5 +1,17 @@
2007-08-23 Jeffrey Stedfast <[EMAIL PROTECTED]>
+ * media.cpp (MediaElement): Initialize 'loaded' to false.
+ (SetSource): Don't call DownloaderComplete() if we haven't been
+ loaded yet.
+ (GetValue): Convert to position from ms to TimeSpan ticks.
+ (OnLoaded): Set loaded to true and, if we have a downloader which
+ has completed the download, call DownloaderComplete() which will
+ then open the media file and autoplay if appropriate.
+ (OnPropertyChanged): Protect against creating a downloader for an
+ empty string uri.
+
+2007-08-23 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
* media.cpp (DownloaderComplete): If we fail to open, emit the
MediaFailedEvent and set some default values.
(OnPropertyChanged): Don't StopLoader() here, do that all in
Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp 2007-08-23 20:44:49 UTC (rev 84751)
+++ trunk/moon/src/media.cpp 2007-08-23 20:47:26 UTC (rev 84752)
@@ -119,9 +119,13 @@
mplayer->SetBalance (media_element_get_balance (this));
mplayer->SetVolume (media_element_get_volume (this));
+ loaded = false;
updating = false;
timeout_id = 0;
+ downloader = NULL;
+ part_name = NULL;
+
BufferingProgressChangedEvent = RegisterEvent
("BufferingProgressChanged");
CurrentStateChangedEvent = RegisterEvent ("CurrentStateChanged");
DownloadProgressChangedEvent = RegisterEvent
("DownloadProgressChanged");
@@ -130,16 +134,15 @@
MediaFailedEvent = RegisterEvent ("MediaFailed");
MediaOpenedEvent = RegisterEvent ("MediaOpened");
- downloader = NULL;
- part_name = NULL;
-
media_element_set_markers (this, new TimelineMarkerCollection ());
}
void
-MediaElement::StopLoader ()
+MediaElement::DownloaderAbort ()
{
if (downloader) {
+ Value *value = downloader->GetValue (Downloader::UriProperty);
+ printf ("aborting downloader for %s\n", value ? value->AsString
() : "(null)");
downloader_abort (downloader);
downloader->unref ();
downloader = NULL;
@@ -152,7 +155,7 @@
g_source_remove (timeout_id);
g_free (part_name);
- StopLoader ();
+ DownloaderAbort ();
delete mplayer;
}
@@ -263,7 +266,7 @@
// Do something with it?
// if size == -1, we do not know the size of the file, can happen
// if the server does not return a Content-Length header
- printf ("The file size is %lld\n", size);
+ //printf ("The video size is %lld\n", size);
}
void
@@ -282,6 +285,8 @@
// FIXME: specify which audio stream index the player should use
+ g_assert (loaded == true);
+
if (!mplayer->Open (filename)) {
media_element_set_can_seek (this, false);
media_element_set_can_pause (this, false);
@@ -306,20 +311,14 @@
media_element_set_current_state (this, "Buffering");
+ Emit (MediaOpenedEvent);
+
Invalidate ();
- // FIXME: if the Source finishes downloading before the xaml
- // parser gets to the AutoPlay="False" property, then we start
- // autoplaying (we need to somehow wait until all properties
- // are read?)
+ printf ("DownloaderComplete: autoplay = %s\n", autoplay ? "true" :
"false");
- if (autoplay) {
+ if (autoplay)
Play ();
- } else {
- media_element_set_current_state (this, "Paused");
- }
-
- Emit (MediaOpenedEvent);
}
void
@@ -331,7 +330,7 @@
if (downloader) {
// Abort the current downloader
- StopLoader ();
+ DownloaderAbort ();
// Abort the current advance_frame timeout
if (timeout_id != 0) {
@@ -354,7 +353,7 @@
downloader->AddHandler (downloader->CompletedEvent,
downloader_complete, this);
if (downloader->Started () || downloader->Completed ()) {
- if (downloader->Completed ())
+ if (loaded && downloader->Completed ())
DownloaderComplete ();
UpdateProgress ();
@@ -385,6 +384,8 @@
void
MediaElement::Play ()
{
+ printf ("MediaElement::Play() requested\n");
+
if (downloader && downloader->Completed () && timeout_id == 0 &&
!mplayer->IsPlaying ()) {
timeout_id = mplayer->Play (advance_frame, this);
media_element_set_current_state (this, "Playing");
@@ -413,7 +414,7 @@
{
if (prop == MediaElement::PositionProperty) {
int64_t position = mplayer->Position ();
- Value v = Value (position, Type::TIMESPAN);
+ Value v = Value (position * TIMESPANTICKS_IN_SECOND / 1000,
Type::TIMESPAN);
updating = true;
SetValue (prop, &v);
@@ -457,14 +458,38 @@
}
void
+MediaElement::OnLoaded ()
+{
+ loaded = true;
+
+ printf ("MediaElement::OnLoaded: ");
+
+ if (downloader && downloader->Completed ()) {
+ printf ("downloader is complete\n");
+ DownloaderComplete ();
+ } else if (downloader) {
+ printf ("downloader not yet completed\n");
+ } else {
+ printf ("no downloader set\n");
+ }
+}
+
+void
MediaElement::OnPropertyChanged (DependencyProperty *prop)
{
if (prop == MediaBase::SourceProperty) {
char *uri = media_base_get_source (this);
- Downloader *dl = new Downloader ();
- downloader_open (dl, "GET", uri);
- SetSource (dl, "");
+ if (uri && *uri) {
+ Downloader *dl = new Downloader ();
+
+ printf ("setting media source to %s\n", uri);
+ downloader_open (dl, "GET", uri);
+ SetSource (dl, "");
+ } else {
+ printf ("trying to set media source to empty\n");
+ DownloaderAbort ();
+ }
} else if (prop == MediaElement::AudioStreamCountProperty) {
// read-only property
} else if (prop == MediaElement::AudioStreamIndexProperty) {
@@ -473,6 +498,7 @@
}
} else if (prop == MediaElement::AutoPlayProperty) {
// no state to change
+ printf ("AutoPlay set to %s\n", media_element_get_auto_play
(this) ? "true" : "false");
} else if (prop == MediaElement::BalanceProperty) {
mplayer->SetBalance (media_element_get_balance (this));
} else if (prop == MediaElement::BufferingProgressProperty) {
@@ -786,13 +812,13 @@
Image::~Image ()
{
- StopLoader ();
+ DownloaderAbort ();
CleanupSurface ();
g_free (part_name);
}
void
-Image::StopLoader ()
+Image::DownloaderAbort ()
{
if (downloader){
downloader_abort (downloader);
@@ -1020,7 +1046,7 @@
// Do something with it?
// if size == -1, we do not know the size of the file, can happen
// if the server does not return a Content-Length header
- printf ("The file size is %lld\n", size);
+ //printf ("The image size is %lld\n", size);
}
void
@@ -1129,8 +1155,8 @@
Image::OnPropertyChanged (DependencyProperty *prop)
{
if (prop == MediaBase::SourceProperty) {
- StopLoader ();
-
+ DownloaderAbort ();
+
char *source = media_base_get_source (this);
Downloader *dl = new Downloader ();
Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h 2007-08-23 20:44:49 UTC (rev 84751)
+++ trunk/moon/src/media.h 2007-08-23 20:47:26 UTC (rev 84752)
@@ -82,7 +82,7 @@
void CreateSurface (const char *fname);
void CleanupSurface ();
void CleanupPattern ();
- void StopLoader ();
+ void DownloaderAbort ();
// downloader callbacks
void PixbufWrite (guchar *bug, gsize offset, gsize count);
@@ -91,9 +91,9 @@
static void pixbuf_write (guchar *buf, gsize offset, gsize count,
gpointer data);
static void downloader_complete (EventObject *sender, gpointer
calldata, gpointer closure);
static void size_notify (int64_t size, gpointer data);
-
+
Downloader *downloader;
-
+
struct CachedSurface {
int ref_cnt;
@@ -122,13 +122,18 @@
class MediaElement : public MediaBase {
+ bool loaded;
+
+ virtual void OnLoaded ();
+
+ void UpdateProgress ();
+
// downloader methods/data
Downloader *downloader;
char *part_name;
- void StopLoader ();
- void UpdateProgress ();
void DataWrite (guchar *data, gsize n, gsize nn);
+ void DownloaderAbort ();
void DownloaderComplete ();
static void data_write (guchar *data, gsize n, gsize nn, void *closure);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches