lundi 20 avril 2015

How to increase the value of a sound file like an uiimagefile

I have the following piece of code:

.h

 #import <UIKit/UIKit.h>

 @interface CardView : UIImageView

 @property (nonatomic) NSInteger pos;
 @property (nonatomic) NSInteger value;

 -(id) initWithFrame: (CGRect)frame andPosition: (NSInteger)pos andValue: (NSInteger)value;
 -(void) flip;

 @end

.m

#import "CardView.h"

@interface CardView()

@property (nonatomic) UIImage *frontImage;
@property (nonatomic) UIImage *backImage;

@end

@implementation CardView

// instantiate custom view subclass programmatically
-(id) initWithFrame: (CGRect)frame andPosition: (NSInteger)pos andValue: (NSInteger)value {
self = [super initWithFrame: frame];
if (self) {
    self.frontImage = [UIImage imageNamed:[NSString stringWithFormat:      @"front%ld.png", (long) (value+1)]];
    self.backImage = [UIImage imageNamed:@"back"];

    self.contentMode = UIViewContentModeScaleAspectFit;
    self.clipsToBounds = YES;
    self.userInteractionEnabled = YES;
    self.image = self.backImage;
    self.value = value;
    self.pos = pos;
  }
  return self;
 }

-(void) flip {
self.image = (self.image == self.frontImage) ? self.backImage : self.frontImage;
}

@end

Ok, seems easy. Just a frame with images. The Images get a value +1. But i can't figure it out how to do that with a sound file. i want to "link up" the image and the related sound file. the files have numbers e.g. front1,front2... and the soundless have sound1, sound2...

thanks for help!

EDIT: something like

self.audioplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSURL   alloc] initFileURLWithPath: [[NSBundle mainBundle]     pathForResource:@"sfx%ld.wav", (long) (value+1)] error:NULL];

doesnt work

Aucun commentaire:

Enregistrer un commentaire