I'm trying to make a QuickTime movie play in my application's dock icon. So far, I've gotten it to each frame into a PicHandle. As it is, my code looks like this:
Controller.h
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> /* Controller */
#import <Cocoa/Cocoa.h>
@interface Controller : NSObject
{
IBOutlet id sourceField;
}
- (IBAction)startPlaying

id)sender;
-(void)playThread

NSString*)string;
@end
</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
Controller.m
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> #import "Controller.h"
#import <QuickTime/QuickTime.h>
#import "DockHandler.h"
@implementation Controller
- (IBAction)startPlaying

id)sender
{
NSLog([sourceField stringValue]);
[NSThread detachNewThreadSelector:@selector(playThread

toTarget:self
withObject:[sourceField stringValue]];
}
-(void)playThread

NSString*)string {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
TimeValue x;
TimeValue duration;
PicHandle thePicture;
NSURL *url = [[NSURL alloc] initFileURLWithPath:@"~/Movies/Xpalm.mp4"];
NSMovie *movie=[[NSMovie alloc] initWithURL:url byReference:YES];
//[NSString stringWithFormat:@"file://%@/%@",NSHomeDirectory,string] byReference:YES];
if(movie !=nil) {
Movie theMovie = [movie QTMovie];
NSLog(string);
[movie release];
EnterMovies();
duration = GetMovieDuration(theMovie);
while(x<duration) {
thePicture = GetMoviePict( theMovie, x );
SetDockIcon( thePicture );
x++;
}
ExitMovies();
}
[pool release];
}
@end
</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
DockHandler.h
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> /*
* DockHandler.h
* WidgetTest
*
* Created by Chris Serino on Fri Jun 30 2000.
* Copyright (c) 2000 __MyCompanyName__. All rights reserved.
*
*/
#include <Carbon/Carbon.h>
void SetDockIcon( PicHandle theBadge ); </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
DockHandler.c
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">
#include <Carbon/Carbon.h>
#include "DockHandler.h"
void SetDockIcon( PicHandle theBadge )
{
OSStatus theErr;
PicHandle theBadgeMask;
GWorldPtr theBadgeWorld;
GWorldPtr theBadgeMaskWorld;
Rect theRect = { 0, 0, 128, 128 };
CGImageRef theBadgeImage;
GDHandle theSavedDevice;
GrafPtr theSavedPort;
// ***
//
// PITFALL!
//
// Rebadging the tile will composite over the old one!
// You might want to restore the tile before badging.
//
// ***
require( theBadge != NULL, CantLoadBadge );
// Make some GWorlds
theErr = NewGWorld( &theBadgeWorld, 32, &theRect, NULL, NULL, 0 );
require_noerr( theErr, CantMakeBadgeWorld );
theErr = NewGWorld( &theBadgeMaskWorld, 32, &theRect, NULL, NULL, 0 );
require_noerr( theErr, CantMakeBadgeMaskWorld );
// Draw the pictures into the GWorlds
GetGWorld( &theSavedPort, &theSavedDevice );
SetGWorld( theBadgeWorld, NULL );
DrawPicture( theBadge, &theRect );
SetGWorld( theBadgeMaskWorld, NULL );
ForeColor( whiteColor );
PaintRect( &theRect );
SetGWorld( theSavedPort, theSavedDevice );
// ***
//
// Make a CGImage from the GWorlds' pixmaps
//
// ***
theErr = CreateCGImageFromPixMaps( GetGWorldPixMap( theBadgeWorld ),
GetGWorldPixMap( theBadgeMaskWorld ), &theBadgeImage );
if ( theErr != noErr )
SysBeep( 0 );
require_noerr( theErr, CantMakeBadgeImage );
// ***
//
// Badge the tile
//
// ***
theErr = OverlayApplicationDockTileImage( theBadgeImage );
if ( theBadgeImage != NULL )
CGImageRelease( theBadgeImage );
CantMakeBadgeMaskWorld:
;
CantMakeBadgeImage:
DisposeGWorld( theBadgeMaskWorld );
CantMakeBadgeWorld:
ReleaseResource( (Handle) theBadgeMask );
CantLoadBadgeMask:
ReleaseResource( (Handle) theBadge );
CantLoadBadge:
;
} </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I know my code is the ugliest thing since the OW icon (j/k I like it, but I couldn't think of anything else), but I'm somewhat of a n00b. Right now I get a linking error. Thanks for your help!
edit: Forgot about my NSImage question. Is there any way to put a PicHandle into an NSImage so I can just use NSApp's setApplicationDockTileImageBlahBlahBlah: method? Again, thanks for your help.
<small>[ 06-30-2002, 05:21 PM: Message edited by: oVeRmInD911 ]</small>