home *** CD-ROM | disk | FTP | other *** search
- /**************************************************
- *
- * Moov stuff
- *
- *
- ***************************************************/
-
- #include "Mini Player3.h"
-
- #include "QuickTimeComponents.h"
-
- extern MovieInstance movieList[];
-
- /**************************************************
- *
- * Globals
- *
- ***************************************************/
-
- /* Info about the movie */
- MovieInstance *activeMovie; /* The frontmost movie */
- short numOpenMovies; /* The number of open movies */
- short checkMovieControllerCount; /* Filter proc uses this instead of rescanning movie list */
- int theModifiers; /* Modifiers from the event record for MovieController filter */
- OSErr theErr; /* Easier than declaring it everywhere */
-
-
- /**************************************************
- *
- * SetUpMovies() Initializes the movie tools
- *
- ***************************************************/
- void SetUpMovies()
-
- {
- int movieCount;
-
- theErr = EnterMovies(); /* This would normally with the other manager inits */
- if (theErr) DebugStr((StringPtr)"\pEnterMovies Failed");
-
-
- /* Clear the array of open movies */
- for (movieCount = 0;movieCount<maxMovies;movieCount++)
- movieList[movieCount].movie = 0;
- activeMovie = 0;
- numOpenMovies = 0; /* None currently open */
-
- }
-
-
- /**************************************************
- *
- * GetAvailMovie()
- * Returns a pointer entry in movieList
- * or 0 if none available
- *
- ***************************************************/
- MovieInstance* GetAvailMovie()
-
- {
- short movieCount;
-
- /* Loop through looking for a match */
- for (movieCount = 0;movieCount<maxMovies;movieCount++)
- if (movieList[movieCount].movie==0)
- break;
- if (movieCount < maxMovies)
- return(&movieList[movieCount]);
-
- return(0L);
-
- }
-
-
- /**************************************************
- *
- * CleanUpMovie(theMovie) Throws out the movie, window, and controller
- *
- ***************************************************/
- void CleanUpMovie(theMovie)
- MovieInstance *theMovie;
-
- {
- if(theMovie->movie) /* if 0, this entry is unused */
- {
- CloseComponent(theMovie->movieController); /* Throw out the controller first */
- DisposeMovie(theMovie->movie); /* Toss the movie */
- theMovie->movie = 0; /* Mark it as unused */
- if(theMovie == activeMovie)
- activeMovie=0;
- DisposeWindow(theMovie->window); /* Toss the window, too */
- numOpenMovies--; /* One less movie to worry about */
- }
- }
-
-
-
- /**************************************************
- *
- * OpenTheMovie(fn,vRef)
- * Opens the movie named fn and starts it up
- *
- ***************************************************/
- void OpenTheMovie(StandardFileReply* sfr)
- {
- static wOffSet = 100;
- MovieInstance *theMovie;
- short movieResRefNum;
- short movieResID;
- Str255 movieName;
- Rect dispBounds;
-
-
- /* First find a space in the movieList Array */
- theMovie = GetAvailMovie();
- if (!theMovie)
- goto bail2;
-
-
- /* First open the movie file */
- if (theErr = OpenMovieFile(&(sfr->sfFile), &movieResRefNum, 0))
- goto bail; /* Bail out if it didn't work */
-
- /* Then the movie in the file */
- theErr = NewMovieFromFile( &(theMovie->movie),movieResRefNum, nil, nil,0, nil );
-
- CloseMovieFile(movieResRefNum); /* We're done with the file */
-
- if(theErr) goto bail;
-
- /* We've got the movie, get the info we need from it */
-
- theMovie->volume = GetMovieVolume(theMovie->movie);
- theMovie->loop = false; /* Default is no looping */
-
- /* Get the bounds for the movie and make sure the top left is 0,0 */
- GetMovieBox( theMovie->movie, &dispBounds);
- OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top);
- SetMovieBox(theMovie->movie, &dispBounds);
-
- /* Create a window for the movie */
- OffsetRect(&dispBounds,wOffSet,wOffSet);
- theMovie->window = (WindowPtr) NewCWindow(0L,&dispBounds,(StringPtr)sfr->sfFile.name,1,4,(WindowPtr)-1L,1,0L);
-
- SetPort(theMovie->window);
-
- SetMovieGWorld(theMovie->movie,nil,nil); /* Play the movie in the window */
-
- /* Get a player thing for the movie */
- MakeMovieControls(theMovie);
- GotoBeginningOfMovie(theMovie->movie);
- PrerollMovie(theMovie->movie,0,0); /* Get everything ready to play */
- SetMovieActive(theMovie->movie, true); /* Needs to be active to play */
- StartMovie(theMovie->movie); /* Start the movie */
-
- numOpenMovies++;
- wOffSet +=16; /* Make next movie a bit more to the lower right */
- if (wOffSet > 300)
- wOffSet = 100; /* But not too far */
-
- return;
-
- /* Cleanup if it didn't work. A nice guy would put up an alert */
- bail:
- if(theMovie->movie)
- {
- DisposeMovie(theMovie->movie);
- theMovie->movie = 0;
- }
- bail2:
- SysBeep(1);
- return;
-
- }
-
- /**************************************************
- ***************************************************
- *
- * Movie Control stuff for making and tracking the controls
- *
- ***************************************************
- ***************************************************/
-
- /**************************************************
- *
- * MakeMovieControls(theMovie) Puts the controls at the bottom of the window
- *
- ***************************************************/
- void MakeMovieControls(theMovie)
- MovieInstance *theMovie;
-
- {
- Component theMovieController;
- ComponentDescription tDesc;
- OSErr theErr;
- Point thePoint;
- Rect bounds, controllerBox;
-
-
- /* Find a movie controller component */
- tDesc.componentType = 'play';
- tDesc.componentSubType = 0;
- tDesc.componentManufacturer = 0;
- tDesc.componentFlags = 0;
- tDesc.componentFlagsMask = 0;
- theMovieController = FindNextComponent( (Component) 0,&tDesc);
-
- /* Get the plaything */
- theMovie->movieController = OpenComponent(theMovieController);
-
- if(theMovie->movieController == nil) /* Did it fail? */
- return;
-
- /* Initialize it */
-
- /* Put it in the window */
- thePoint.h = (theMovie->window)->portRect.left;
- thePoint.v = (theMovie->window)->portRect.top;
- theErr = MCNewAttachedController(theMovie->movieController,theMovie->movie,
- theMovie->window,thePoint);
- /* Calc the new size for the window */
- GetMovieBox(theMovie->movie,&bounds); /* We made the top left 0,0 earlier */
- MCGetControllerBoundsRect(theMovie->movieController,&controllerBox);
- UnionRect(&bounds,&controllerBox,&bounds);
- SizeWindow( theMovie->window,bounds.right,bounds.bottom,true);
-
- /* Filter for events we want to know about */
- MCSetActionFilter(theMovie->movieController,(MCActionFilter) MyPlayerFilter);
-
-
- }
-
- /**************************************************
- *
- * MyPlayerFilter() Puts the controls at the bottom of the window
- *
- * Catches player events I'm interested in
- *
- * YOU don't have to do this filter
- * I'm doing it to show how a filter works.
- *
- * Activate/ deactivate events are filtered so I can give
- * extra time to the active window and reduce the volume of back windows
- *
- * The play event is to loop the movie if the shift key is pressed
- *
- ***************************************************/
- pascal Boolean MyPlayerFilter(MovieController pt, short *action, void *params)
-
- {
- Boolean wasHandled = false;
- long loopFlag;
- short mCount;
-
- switch( *action)
- {
- case mcActionActivate:
- DoMovieActivate(&movieList[checkMovieControllerCount]);
- break;
-
- case mcActionDeactivate:
- DoMovieDeactivate(&movieList[checkMovieControllerCount]);
- break;
-
- case mcActionPlay:
- loopFlag = (theModifiers & (shiftKey | controlKey)) != 0; /* Shift key pressed? */
- theErr = MCDoAction(pt,mcActionSetLooping,(void *) loopFlag);
- loopFlag = (theModifiers & controlKey) != 0; /* Control key pressed? */
- theErr = MCDoAction(pt,mcActionSetLoopIsPalindrome,(void *) loopFlag);
- break;
-
- case mcActionPlayBackwards:
- loopFlag = (theModifiers & (shiftKey | controlKey)) != 0; /* Shift key pressed? */
- theErr = MCDoAction(pt,mcActionSetLooping,(void *) loopFlag);
- loopFlag = (theModifiers & controlKey) != 0; /* Control key pressed? */
- theErr = MCDoAction(pt,mcActionSetLoopIsPalindrome,(void *) loopFlag);
- break;
-
- }
-
- return(wasHandled);
-
- }
-
-
- /**************************************************
- ***************************************************
- *
- * Movie Event stuff
- *
- ***************************************************
- ***************************************************/
- /**************************************************
- *
- * CheckMovieControllers() Checks if the event is handled by any of the
- * playthings returns true if the event was handled
- *
- ***************************************************/
- Boolean CheckMovieControllers(EventRecord *theEvent)
-
- {
-
- short mCount;
- Boolean eventHandled = false;
-
- /* Loop through all of the movies */
- for(checkMovieControllerCount = 0;checkMovieControllerCount<maxMovies;checkMovieControllerCount++)
- {
- if (movieList[checkMovieControllerCount].movie)
- if (eventHandled = MCIsPlayerEvent(movieList[checkMovieControllerCount].movieController, theEvent)) /* Was it handled? */
- break; /* If so, return */
- }
-
- return(eventHandled);
- }
-
- /**************************************************
- *
- * MyMoviesTask() Calls MoviesTask and stops at the end
- * This is called from the main event loop of the application
- * The active movie is serviced every time to get smooth play
- * The other movies are serviced by the MovieController
- *
- ***************************************************/
- void MyMoviesTask()
-
- {
-
- /* Sevice the activeMovie if there is one */
- if(activeMovie)
- {
- MoviesTask(activeMovie->movie,1);
- }
-
-
-
- }
-
- /**************************************************
- *
- * MovieMouseDown(theWindow, thePoint, int theModifiers)
- * Mouse pressed in movie content
- * I don't have anything here since the MovieController does it all for me!
- *
- ***************************************************/
- void MovieMouseDown(WindowPtr theWindow, Point thePoint, int theModifiers)
-
- {
-
- }
-
-
- /**************************************************
- *
- * DoMovieUpdate()
- *
- * Updates the movie screen
- * I don't have anything here since the MovieController does it all for me!
- *
- ***************************************************/
- void DoMovieUpdate(theMovie)
- MovieInstance *theMovie;
- {
-
- }
-
- /**************************************************
- *
- * DoMovieActivate(theMovie)
- *
- * Highlights the controls
- *
- ***************************************************/
- void DoMovieActivate(theMovie)
- MovieInstance *theMovie;
-
- {
-
- /* Restore the volume in case it was reduced */
- SetMovieVolume(theMovie->movie,theMovie->volume);
-
- activeMovie = theMovie;
-
- }
-
- /**************************************************
- *
- * DoMovieDeactivate(theMovie)
- *
- * gray out the controls
- *
- ***************************************************/
- void DoMovieDeactivate(theMovie)
- MovieInstance *theMovie;
-
- {
- if (theMovie)
- {
-
- /* Save the volume and reduce it */
- theMovie->volume = GetMovieVolume(theMovie->movie);
- SetMovieVolume(theMovie->movie,theMovie->volume/3);
-
- activeMovie = 0; /* no active movie */
- }
- }
-
-