X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c560088c4d59dbb12680c07d8892506688f09220..7c60222510bc5e197b12f153c4bf05db66cb0f4a:/src/osx/cocoa/mediactrl.mm?ds=sidebyside diff --git a/src/osx/cocoa/mediactrl.mm b/src/osx/cocoa/mediactrl.mm index 33381967df..7faa4bc3a2 100644 --- a/src/osx/cocoa/mediactrl.mm +++ b/src/osx/cocoa/mediactrl.mm @@ -55,9 +55,6 @@ #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" -#import -#import - class WXDLLIMPEXP_FWD_MEDIA wxQTMediaBackend; @interface wxQTMovie : QTMovie { @@ -191,20 +188,21 @@ private: } } --(void)loadStateChanged:(QTMovie *)movie +-(void)loadStateChanged:(NSNotification *)notification { + QTMovie *movie = [notification object]; long loadState = [[movie attributeForKey:QTMovieLoadStateAttribute] longValue]; - if (loadState >= QTMovieLoadStatePlayable) + if ( loadState == QTMovieLoadStateError ) { - // the movie has loaded enough media data to begin playing + // error occurred } - else if (loadState >= QTMovieLoadStateLoaded) + else if (loadState >= QTMovieLoadStatePlayable) { - m_backend->FinishLoad(); + // the movie has loaded enough media data to begin playing, but we don't have an event for that yet } - else if (loadState == -1) + else if (loadState >= QTMovieLoadStateComplete) // we might use QTMovieLoadStatePlaythroughOK { - // error occurred + m_backend->FinishLoad(); } } @@ -227,8 +225,8 @@ private: IMPLEMENT_DYNAMIC_CLASS(wxQTMediaBackend, wxMediaBackend); wxQTMediaBackend::wxQTMediaBackend() : - m_interfaceflags(wxMEDIACTRLPLAYERCONTROLS_NONE), - m_movie(nil), m_movieview(nil) + m_movie(nil), m_movieview(nil), + m_interfaceflags(wxMEDIACTRLPLAYERCONTROLS_NONE) { } @@ -283,13 +281,30 @@ bool wxQTMediaBackend::Load(const wxString& fileName) bool wxQTMediaBackend::Load(const wxURI& location) { wxCFStringRef uri(location.BuildURI()); - - [m_movie release]; - wxQTMovie* movie = [[wxQTMovie alloc] initWithURL: [NSURL URLWithString: uri.AsNSString()] error: nil ]; + NSURL *url = [NSURL URLWithString: uri.AsNSString()]; + if (! [wxQTMovie canInitWithURL:url]) + return false; + + [m_movie release]; + wxQTMovie* movie = [[wxQTMovie alloc] initWithURL:url error: nil ]; + m_movie = movie; - [m_movie setBackend:this]; - [m_movieview setMovie:movie]; + if (movie != nil) + { + [m_movie setBackend:this]; + [m_movieview setMovie:movie]; + + // If the media file is able to be loaded quickly then there may not be + // any QTMovieLoadStateDidChangeNotification message sent, so we need to + // also check the load state here and finish our initialization if it has + // been loaded. + long loadState = [[m_movie attributeForKey:QTMovieLoadStateAttribute] longValue]; + if (loadState >= QTMovieLoadStateComplete) + { + FinishLoad(); + } + } return movie != nil; } @@ -298,12 +313,10 @@ void wxQTMediaBackend::FinishLoad() { DoShowPlayerControls(m_interfaceflags); - NSRect r =[m_movieview movieBounds]; - m_bestSize.x = r.size.width; - m_bestSize.y = r.size.height; + NSSize s = [[m_movie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue]; + m_bestSize = wxSize(s.width, s.height); NotifyMovieLoaded(); - } bool wxQTMediaBackend::Play() @@ -394,6 +407,7 @@ wxSize wxQTMediaBackend::GetVideoSize() const void wxQTMediaBackend::Move(int x, int y, int w, int h) { + // as we have a native player, no need to move the video area } bool wxQTMediaBackend::ShowPlayerControls(wxMediaCtrlPlayerControls flags) @@ -413,6 +427,8 @@ void wxQTMediaBackend::DoShowPlayerControls(wxMediaCtrlPlayerControls flags) } else { + [m_movieview setControllerVisible:YES]; + [m_movieview setStepButtonsVisible:(flags & wxMEDIACTRLPLAYERCONTROLS_STEP) ? YES:NO]; [m_movieview setVolumeButtonVisible:(flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME) ? YES:NO]; }