• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
(no subject)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(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 unarchiveObjectWithData: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.

  • Prev by Date: Re: setKeyEquivalent and function keys
  • Next by Date: Re: NSString Parsing
  • Previous by thread: Re: (no subject)
  • Next by thread: Status of SDK/APIs for iCal & iSync
  • Index(es):
    • Date
    • Thread