Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 多音频播放器_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 多音频播放器

Iphone 多音频播放器,iphone,objective-c,xcode,Iphone,Objective C,Xcode,有人能告诉我如何编程一个具有翻页效果声音的小应用程序吗。 我希望有人点击“下一步”按钮,声音播放1秒并将我带到第二页,从第二页开始,如果你点击“上一步”按钮,另一个声音播放1秒并将你带回到原始页。 不知何故,我遇到了一个问题,当我点击后退按钮时,模拟器崩溃并显示自动释放错误消息。请查找下面的.h和.m文件。感谢您抽出时间阅读 这是第1页的.m文件 #import "_0_RabbanasViewController.h" #import "Rabbana2.h" #import "InfoPag

有人能告诉我如何编程一个具有翻页效果声音的小应用程序吗。 我希望有人点击“下一步”按钮,声音播放1秒并将我带到第二页,从第二页开始,如果你点击“上一步”按钮,另一个声音播放1秒并将你带回到原始页。 不知何故,我遇到了一个问题,当我点击后退按钮时,模拟器崩溃并显示自动释放错误消息。请查找下面的.h和.m文件。感谢您抽出时间阅读

这是第1页的.m文件

#import "_0_RabbanasViewController.h"
#import "Rabbana2.h"
#import "InfoPage.h"

@implementation _0_RabbanasViewController



- (IBAction)info {

    // This part takes us to the info page
    InfoPage *info = [[InfoPage alloc] initWithNibName:@"InfoPage" bundle:nil];
    [UIView beginAnimations:@"flipView" context:Nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
    [self.view addSubview:info.view];
    [info release];
    [UIView commitAnimations];


    // This part plays the next page turn noise
    NSURL *this = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/next.wav", [[NSBundle mainBundle] resourcePath]]];
    NSError *error;
    pagePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:this error:&error];
    [pagePlayer setDelegate:self];
    pagePlayer.numberOfLoops = 0;
    [pagePlayer play];
    //[pagePlayer release];

    //This will stop the music when turning page
    [audioPlayer stop];
    [audioPlayer release];
    clicked = 0;
    [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal];

}

- (IBAction)next {

    // This part takes us to the next view
    Rabbana2 *next = [[Rabbana2 alloc] initWithNibName:@"Rabbana2" bundle:nil];
    [UIView beginAnimations:@"flipView" context:Nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
    [self.view addSubview:next.view];
    //[next release];
    [UIView commitAnimations];



    // This part plays the next page turn noise
    NSURL *this = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/next.wav", [[NSBundle mainBundle] resourcePath]]];
    NSError *error;
    pagePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:this error:&error];
    [pagePlayer setDelegate:self];
    pagePlayer.numberOfLoops = 0;
    [pagePlayer play];
     //[pagePlayer release];

    //This will stop the music when turning page
    [audioPlayer release];
    clicked = 0;
    [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal]; 

}

// This button plays the audio
- (IBAction)play {

    if(clicked == 0){
        clicked = 1;
        NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/rabbana1.wav", [[NSBundle mainBundle] resourcePath]]];

        NSError *error;
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
        [audioPlayer setDelegate:self];
        audioPlayer.numberOfLoops = 0;


        [audioPlayer play];
        [start setImage:[UIImage imageNamed:@"Sstop.png"] forState:UIControlStateNormal];

    } 
    else{
        [audioPlayer stop];
        [audioPlayer release];
        clicked = 0;
        [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal];
    } 

}

//If user does not do anything by the end of the sound set the button to start
- (void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player
                        successfully: (BOOL) flag {
    if (flag==YES) {
        clicked = 0;
        [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal];
    }
}
/*
// If user click on the next button while audio playing, Audio should stop
- (void) audioPlayerDidNotFinishPlaying: (AVAudioPlayer *) player
                                success: (BOOL) flag {
    if (flag==YES) {
        [audioPlayer stop];
        [audioPlayer release];
        clicked = 0;
        [start setImage:[UIImage imageNamed:@"Pplay.png"] forState:UIControlStateNormal];
    }
}
*/

- (void)dealloc
{

    [super dealloc];
    //[self.pagePlayer.delegate = nil];
    //self.AVAudioPlayer = nil ;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    [scroll setScrollEnabled:YES];
    [scroll setContentSize:CGSizeMake(275,445)];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    //[audioPlayer release];
    //[pagePlayer release];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
这是第2页的.m文件

#import "InfoPage.h"
#import "_0_RabbanasViewController.h"


@implementation InfoPage

- (IBAction)back {
    [UIView beginAnimations:@"flipView" context:Nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationCurve:UIViewAnimationOptionCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES];

    [self.view removeFromSuperview];
    [UIView commitAnimations];

    // This part plays the back page turn noise
    NSURL *this = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/back.wav", [[NSBundle mainBundle] resourcePath]]];
    NSError *error;
    pagePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:this error:&error];
    [pagePlayer setDelegate:self];
    pagePlayer.numberOfLoops = 0;
    [pagePlayer play];

    //This will stop the music when turning page
    [pagePlayer release];
    clicked = 0;


}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
   // [InfoPage dealloc];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   // [pagePlayer release];
    self.view = nil;
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [scroll setScrollEnabled:YES];
    [scroll setContentSize:CGSizeMake(320,480)];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end