Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Restore sound selector; move most of the preview functionality (exclu…

…ding validation) to QTKit as NSMovieView and QuickTime are deprecated. Hopefully this will improve stability as well.

git-svn-id: http://dev.sabi.net/svn/dev/trunk/Cocoa/Pester@533 24bc951d-4bb6-0310-a7b7-f2527510289e
  • Loading branch information...
commit 8724c4e278454914e5262524c9353d5bbf0e4e41 1 parent f517962
@nriley authored
View
4 Source/English.lproj/MainMenu.nib/classes.nib
@@ -174,7 +174,7 @@
<key>OUTLETS</key>
<dict>
<key>preview</key>
- <string>NSMovieView</string>
+ <string>QTMovieView</string>
</dict>
<key>SUPERCLASS</key>
<string>NSPopUpButton</string>
@@ -199,7 +199,7 @@
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
- <string>NSMovieView</string>
+ <string>QTMovieView</string>
</dict>
<dict>
<key>CLASS</key>
View
2  Source/English.lproj/MainMenu.nib/info.nib
@@ -10,7 +10,7 @@
<integer>4</integer>
<key>IBOpenObjects</key>
<array>
- <integer>2</integer>
+ <integer>507</integer>
</array>
<key>IBSystem Version</key>
<string>9J61</string>
View
BIN  Source/English.lproj/MainMenu.nib/keyedobjects.nib
Binary file not shown
View
3  Source/NJRQTMediaPopUpButton.h
@@ -7,12 +7,13 @@
//
#import <AppKit/AppKit.h>
+#import <QTKit/QTKit.h>
#import "BDAlias.h"
extern NSString * const NJRQTMediaPopUpButtonMovieChangedNotification;
@interface NJRQTMediaPopUpButton : NSPopUpButton {
- IBOutlet NSMovieView *preview;
+ IBOutlet QTMovieView *preview;
BOOL movieCanRepeat, movieHasAudio;
NSMenuItem *otherItem;
BDAlias *selectedAlias, *previousAlias;
View
68 Source/NJRQTMediaPopUpButton.m
@@ -13,7 +13,6 @@
#import <QTKit/QTKit.h>
-#include <QuickTime/Movies.h>
#include <limits.h>
static const int NJRQTMediaPopUpButtonMaxRecentItems = 10;
@@ -24,8 +23,9 @@ @interface NJRQTMediaPopUpButton (Private)
- (void)_setPath:(NSString *)path;
- (NSMenuItem *)_itemForAlias:(BDAlias *)alias;
- (BOOL)_validateWithPreview:(BOOL)doPreview;
-- (void)_updateOutputVolume;
- (void)_startSoundPreview;
+- (void)_resetPreview;
+- (void)_resetOutputVolume;
@end
@implementation NJRQTMediaPopUpButton
@@ -303,8 +303,8 @@ - (void)setOutputVolume:(float)volume withPreview:(BOOL)doPreview;
// NSLog(@"setting volume to %f, preview movie %@", volume, [preview movie]);
if ([preview movie] == nil) {
[self _validateWithPreview: YES];
- } else { // don't restart preview if already playing
- [self _updateOutputVolume];
+ } else {
+ [self _startSoundPreview];
}
}
@@ -317,57 +317,46 @@ - (void)_invalidateSelection;
[[NSNotificationCenter defaultCenter] postNotificationName: NJRQTMediaPopUpButtonMovieChangedNotification object: self];
}
-- (void)_updateOutputVolume;
+- (void)_startSoundPreview;
{
- if ([preview movie] != nil && outputVolume != kNoVolume) {
- if (!savedVolume && ![NJRSoundManager saveDefaultOutputVolume])
- return;
+ if ([preview movie] == nil || outputVolume == kNoVolume)
+ return;
+
+ if (savedVolume || [NJRSoundManager saveDefaultOutputVolume]) {
savedVolume = YES;
[NJRSoundManager setDefaultOutputVolume: outputVolume];
- if (![preview isPlaying]) [self _startSoundPreview];
}
-}
-- (void)_resetOutputVolume;
-{
- [NJRSoundManager restoreSavedDefaultOutputVolumeIfCurrently: outputVolume];
- savedVolume = NO;
+ if ([[preview movie] rate] != 0)
+ return; // don't restart preview if already playing
+
+ [[NSNotificationCenter defaultCenter] addObserver: self
+ selector: @selector(_soundPreviewDidEnd:)
+ name: QTMovieDidEndNotification
+ object: [preview movie]];
+ [preview play: self];
}
-- (void)_resetPreview;
+- (void)_soundPreviewDidEnd:(NSNotification *)notification;
{
- // 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
- [preview setMovie: nil]; // otherwise we get an extra runloop timer which uses a lot of CPU from +[NSMovieView _idleMovies]
- // need to wait for runloop to stop movie, otherwise we're still playing at the time the volume changes
- [self performSelector: @selector(_resetOutputVolume) withObject: nil afterDelay: 0];
+ [self _resetPreview];
}
-void
-MovieStoppedCB(QTCallBack cb, long refCon)
+- (void)_resetPreview;
{
- NJRQTMediaPopUpButton *self = (NJRQTMediaPopUpButton *)refCon;
- // avoid multiple messages from multiple movie playback cycles in the same runloop
- [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_resetPreview) object: nil];
- [self performSelector: @selector(_resetPreview) withObject: nil afterDelay: 0];
- DisposeCallBack(cb);
+ [preview setMovie: nil];
+ [self _resetOutputVolume];
}
-- (void)_startSoundPreview;
+- (void)_resetOutputVolume;
{
- Movie qtMovie = [[preview movie] QTMovie];
- QTCallBack cbStop = NewCallBack(GetMovieTimeBase(qtMovie), callBackAtExtremes);
- QTCallBackUPP cbStopUPP = NewQTCallBackUPP(MovieStoppedCB);
- OSErr err = CallMeWhen(cbStop, cbStopUPP, (long)self, triggerAtStop, 0, 0);
- if (err != noErr) {
- NSLog(@"Can't register QuickTime stop timebase callback for preview: %ld", err);
- DisposeCallBack(cbStop);
- }
- [preview start: self];
+ [NJRSoundManager restoreSavedDefaultOutputVolumeIfCurrently: outputVolume];
+ savedVolume = NO;
}
- (BOOL)_validateWithPreview:(BOOL)doPreview;
{
- [preview stop: self];
+ [preview pause: self];
if (selectedAlias == nil) {
[preview setMovie: nil];
movieCanRepeat = YES;
@@ -381,8 +370,7 @@ - (BOOL)_validateWithPreview:(BOOL)doPreview;
NSMovie *movie = [[NSMovie alloc] initWithURL: [NSURL fileURLWithPath: [selectedAlias fullPath]] byReference: YES];
movieCanRepeat = ![movie isStatic];
if (movieHasAudio = [movie hasAudio]) {
- [preview setMovie: doPreview ? movie : nil];
- [self _updateOutputVolume];
+ [preview setMovie: doPreview ? [QTMovie movieWithURL: [NSURL fileURLWithPath: [selectedAlias fullPath]] error: NULL] : nil]; // XXX handle errors; fix
} else {
[self _resetPreview];
doPreview = NO;
@@ -411,7 +399,7 @@ - (BOOL)_validateWithPreview:(BOOL)doPreview;
- (IBAction)stopSoundPreview:(id)sender;
{
- [preview stop: self];
+ [preview pause: self];
[self _resetPreview];
}
View
4 Source/NJRUnfocusableMovieView.h
@@ -7,9 +7,9 @@
//
#import <AppKit/AppKit.h>
+#import <QTKit/QTKit.h>
-
-@interface NJRUnfocusableMovieView : NSMovieView {
+@interface NJRUnfocusableMovieView : QTMovieView {
}
Please sign in to comment.
Something went wrong with that request. Please try again.