Changeset 133 for trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
- Timestamp:
- 04/09/03 05:44:11 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/NJRQTMediaPopUpButton.m
r103 r133 9 9 #import "NJRQTMediaPopUpButton.h" 10 10 #import "SoundFileManager.h" 11 #import "NJRSoundManager.h" 11 12 #import "NSMovie-NJRExtensions.h" 12 13 #import "NSImage-NJRExtensions.h" … … 27 28 - (NSMenuItem *)_itemForAlias:(BDAlias *)alias; 28 29 - (BOOL)_validateWithPreview:(BOOL)doPreview; 30 - (void)_updateOutputVolume; 31 - (void)_startSoundPreview; 29 32 @end 30 33 … … 267 270 } 268 271 272 - (BOOL)hasAudio; 273 { 274 return movieHasAudio; 275 } 276 277 - (float)outputVolume; 278 { 279 return outputVolume; 280 } 281 282 - (void)setOutputVolume:(float)volume withPreview:(BOOL)doPreview; 283 { 284 if (![NJRSoundManager volumeIsNotMutedOrInvalid: volume]) return; 285 outputVolume = volume; 286 if (!doPreview) return; 287 // NSLog(@"setting volume to %f, preview movie %@", volume, [preview movie]); 288 if ([preview movie] == nil) { 289 [self _validateWithPreview: YES]; 290 } else { // don't restart preview if already playing 291 [self _updateOutputVolume]; 292 } 293 } 294 269 295 #pragma mark selected media validation 270 296 … … 276 302 } 277 303 304 - (void)_updateOutputVolume; 305 { 306 if ([preview movie] != nil && outputVolume != kNoVolume) { 307 if (!savedVolume && ![NJRSoundManager saveDefaultOutputVolume]) 308 return; 309 savedVolume = YES; 310 [NJRSoundManager setDefaultOutputVolume: outputVolume]; 311 if (![preview isPlaying]) [self _startSoundPreview]; 312 } 313 } 314 315 - (void)_resetOutputVolume; 316 { 317 [NJRSoundManager restoreSavedDefaultOutputVolumeIfCurrently: outputVolume]; 318 savedVolume = NO; 319 } 320 321 - (void)_resetPreview; 322 { 323 // if we donÕt do this after the runloop has finished, then we crash in MCIdle because itÕs expecting a movie and doesnÕt have one any more 324 [preview setMovie: nil]; // otherwise we get an extra runloop timer which uses a lot of CPU from +[NSMovieView _idleMovies] 325 // need to wait for runloop to stop movie, otherwise we're still playing at the time the volume changes 326 [self performSelector: @selector(_resetOutputVolume) withObject: nil afterDelay: 0]; 327 } 328 278 329 void 279 330 MovieStoppedCB(QTCallBack cb, long refCon) 280 331 { 281 NSMovieView *preview = (NSMovieView *)refCon; 282 // if we donÕt do this after the runloop has finished, then we crash in MCIdle because itÕs expecting a movie and doesnÕt have one any more 283 [preview performSelector: @selector(setMovie:) withObject: nil afterDelay: 0]; // otherwise we get an extra runloop timer which uses a lot of CPU from +[NSMovieView _idleMovies] 332 NJRQTMediaPopUpButton *self = (NJRQTMediaPopUpButton *)refCon; 333 // avoid multiple messages from multiple movie playback cycles in the same runloop 334 [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_resetPreview) object: nil]; 335 [self performSelector: @selector(_resetPreview) withObject: nil afterDelay: 0]; 284 336 DisposeCallBack(cb); 337 } 338 339 - (void)_startSoundPreview; 340 { 341 Movie qtMovie = [[preview movie] QTMovie]; 342 QTCallBack cbStop = NewCallBack(GetMovieTimeBase(qtMovie), callBackAtExtremes); 343 QTCallBackUPP cbStopUPP = NewQTCallBackUPP(MovieStoppedCB); 344 OSErr err = CallMeWhen(cbStop, cbStopUPP, (long)self, triggerAtStop, 0, 0); 345 if (err != noErr) { 346 NSLog(@"Can't register QuickTime stop timebase callback for preview: %ld", err); 347 DisposeCallBack(cbStop); 348 } 349 [preview start: self]; 285 350 } 286 351 … … 291 356 [preview setMovie: nil]; 292 357 movieCanRepeat = YES; 293 if (doPreview) NSBeep(); 358 movieHasAudio = NO; // XXX should be YES - this is broken, NSBeep() is asynchronous 359 if (doPreview) { 360 // XXX [self _updateOutputVolume]; 361 NSBeep(); 362 // XXX [self _resetOutputVolume]; 363 } 294 364 } else { 295 365 NSMovie *movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: [selectedAlias fullPath]] byReference: YES]; 296 366 movieCanRepeat = ![movie isStatic]; 297 if ( [movie hasAudio]) {367 if (movieHasAudio = [movie hasAudio]) { 298 368 [preview setMovie: doPreview ? movie : nil]; 369 [self _updateOutputVolume]; 299 370 } else { 300 [preview setMovie: nil]; 371 [self _resetPreview]; 372 doPreview = NO; 301 373 if (movie == nil) { 302 374 NSBeginAlertSheet(@"Format not recognized", nil, nil, nil, [self window], nil, nil, nil, nil, NSLocalizedString(@"The item you selected isn't a sound or movie recognized by QuickTime. Please select a different item.", "Message displayed in alert sheet when media document is not recognized by QuickTime")); … … 312 384 } 313 385 if (doPreview) { 314 Movie qtMovie = [movie QTMovie]; 315 QTCallBack cbStop = NewCallBack(GetMovieTimeBase(qtMovie), callBackAtExtremes); 316 QTCallBackUPP cbStopUPP = NewQTCallBackUPP(MovieStoppedCB); 317 OSErr err = CallMeWhen(cbStop, cbStopUPP, (long)preview, triggerAtStop, 0, 0); 318 if (err != noErr) { 319 NSLog(@"Can't register QuickTime stop timebase callback for preview: %ld", err); 320 DisposeCallBack(cbStop); 321 } 322 [preview start: self]; 386 [self _startSoundPreview]; 323 387 } 324 388 [movie release]; … … 333 397 { 334 398 [preview stop: self]; 335 [ preview setMovie: nil]; // otherwise we get an extra runloop timer which uses a lot of CPU from +[NSMovieView _idleMovies]399 [self _resetPreview]; 336 400 } 337 401
Note:
See TracChangeset
for help on using the changeset viewer.