#include "wx/cocoa/autorelease.h"
#include "wx/cocoa/string.h"
-#import <AppKit/NSMovie.h>
-#import <AppKit/NSMovieView.h>
-
class WXDLLIMPEXP_FWD_MEDIA wxQTMediaBackend;
@interface wxQTMovie : QTMovie {
}
}
--(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();
}
}
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)
{
}
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;
}
{
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()
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)
}
else
{
+ [m_movieview setControllerVisible:YES];
+
[m_movieview setStepButtonsVisible:(flags & wxMEDIACTRLPLAYERCONTROLS_STEP) ? YES:NO];
[m_movieview setVolumeButtonVisible:(flags & wxMEDIACTRLPLAYERCONTROLS_VOLUME) ? YES:NO];
}