(no subject)
(no subject)
- Subject: (no subject)
- From: Bob Peterson <email@hidden>
- Date: Tue, 29 Oct 2002 17:05:06 -0500
I am not able to play an NSSound object which has been unarchived from
an original that was loaded with byReference:NO. The play method
returns false.
If I load the original using byReference:YES, it works. I've attached
some code that demonstrates my procedure. Have I done something wrong?
I've searched the cocoa-dev archives. I've tried wav, mp3 and aiff
files.
\bob peterson
/* AppController */
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject
{
NSSound* sound;
NSSound* sound2;
}
- (IBAction)playSound:(id)sender;
- (IBAction)playSound2:(id)sender;
@end
#import "AppController.h"
@implementation AppController
- (id)init
{
if (self = [super init]) {
NSString* soundPathName;
if (soundPathName = [[NSBundle mainBundle]
pathForResource:@"test sound" ofType:@"wav" inDirectory:nil] ) {
if (sound = [[NSSound alloc]
initWithContentsOfFile:soundPathName byReference:NO]) {
NSData* data;
data = [NSArchiver archivedDataWithRootObject:sound];
sound2 = [[NSUnarchiver unarchiveObjectWith
Data:data]
retain];
NSLog(@"init and cloned sound");
}
else {
NSLog(@"Couldn't init");
}
}
else {
NSLog(@"No resource");
}
}
return self;
}
- (IBAction)playSound:(id)sender
{
if ([sound play]) {
NSLog(@"Sound play = YES");
}
else {
NSLog(@"Sound play = NO");
}
}
- (IBAction)playSound2:(id)sender
{
if ([sound2 play]) {
NSLog(@"Sound2 play = YES");
}
else {
NSLog(@"Sound2 play = NO");
}
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.