00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00033
00034 #ifndef GROOVX_MEDIA_QUICKTIMESOUND_H_UTC20050626084018_DEFINED
00035 #define GROOVX_MEDIA_QUICKTIMESOUND_H_UTC20050626084018_DEFINED
00036
00037 #include "media/soundrep.h"
00038
00039 #include "rutz/error.h"
00040 #include "rutz/fstring.h"
00041 #include "rutz/sfmt.h"
00042
00043 #include <Carbon/Carbon.h>
00044 #include <QuickTime/Movies.h>
00045
00046 #include "rutz/trace.h"
00047 #include "rutz/debug.h"
00048
00049 namespace media
00050 {
00052 class quicktime_sound_rep : public sound_rep
00053 {
00054 public:
00055 quicktime_sound_rep(const char* filename);
00056
00057 virtual ~quicktime_sound_rep() throw();
00058
00059 virtual void play();
00060
00061 bool init_sound();
00062 void close_sound();
00063
00064 short m_file_ref_num;
00065 Movie m_movie;
00066
00067 static bool quicktime_inited;
00068 };
00069 }
00070
00071 bool media::quicktime_sound_rep::quicktime_inited = false;
00072
00073 media::quicktime_sound_rep::quicktime_sound_rep(const char* filename)
00074 {
00075 GVX_TRACE("media::quicktime_sound_rep::quicktime_sound_rep");
00076
00077 init_sound();
00078
00079
00080 FSRef ref;
00081
00082 OSErr err = FSPathMakeRef(reinterpret_cast<const UInt8*>(filename),
00083 &ref, 0);
00084
00085 if (noErr != err)
00086 throw rutz::error(rutz::sfmt("error in FSPathMakeRef: %d", int(err)),
00087 SRC_POS);
00088
00089
00090 FSSpec spec;
00091
00092 err = FSGetCatalogInfo(&ref, kFSCatInfoNone,
00093 NULL, NULL, &spec, NULL);
00094
00095 if (noErr != err)
00096 throw rutz::error(rutz::sfmt("error in FSGetCatalogInfo: %d", int(err)),
00097 SRC_POS);
00098
00099
00100 err = OpenMovieFile(&spec, &m_file_ref_num, fsRdPerm);
00101
00102 if (noErr != err)
00103 throw rutz::error(rutz::sfmt("error in OpenMovieFile: %d", int(err)),
00104 SRC_POS);
00105
00106
00107 err = NewMovieFromFile(&m_movie, m_file_ref_num, 0, nil,
00108 newMovieActive, nil);
00109
00110 if (noErr != err)
00111 {
00112 CloseMovieFile(m_file_ref_num);
00113 throw rutz::error(rutz::sfmt("error in NewMovieFromFile: %d", int(err)),
00114 SRC_POS);
00115 }
00116 }
00117
00118 media::quicktime_sound_rep::~quicktime_sound_rep() throw()
00119 {
00120 GVX_TRACE("media::quicktime_sound_rep::~quicktime_sound_rep");
00121 DisposeMovie(m_movie);
00122 CloseMovieFile(m_file_ref_num);
00123 }
00124
00125 void media::quicktime_sound_rep::play()
00126 {
00127 GVX_TRACE("media::quicktime_sound_rep::play");
00128 GoToBeginningOfMovie(m_movie);
00129
00130 StartMovie(m_movie);
00131
00132 while (!IsMovieDone (m_movie))
00133 {
00134 MoviesTask(m_movie, 0);
00135 }
00136 }
00137
00138 bool media::quicktime_sound_rep::init_sound()
00139 {
00140 GVX_TRACE("media::quicktime_sound_rep::init_sound");
00141 if (!quicktime_inited)
00142 {
00143 const OSErr err = EnterMovies();
00144
00145 if (noErr == err)
00146 quicktime_inited = true;
00147 }
00148
00149 return quicktime_inited;
00150 }
00151
00152 void media::quicktime_sound_rep::close_sound()
00153 {
00154 GVX_TRACE("quicktime_sound_rep::close_sound");
00155 if (quicktime_inited)
00156 {
00157 ExitMovies();
00158 }
00159 }
00160
00161 static const char __attribute__((used)) vcid_groovx_media_quicktimesound_h_utc20050626084018[] = "$Id: quicktimesound.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00162 #endif // !GROOVX_MEDIA_QUICKTIMESOUND_H_UTC20050626084018_DEFINED