微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

参照图像播放声音

如何解决参照图像播放声音

| 如问题中所述,我向资源文件添加了一些图像和声音文件。使用下一个和上一个按钮,图像导航可以正常工作。现在,我需要播放与图像相关的声音。工作代码如下所示。我需要知道该怎么做才能使声音播放图像。 我添加了audioToolBox.framework和AVFoundation.framework。我已经在Apple开发人员网站上阅读了有关“ 0”的信息。
#import \"next_prevIoUsViewController.h\"

@implementation next_prevIoUsViewController

@synthesize image1,next1,next2;

NSMutableArray *list;
NSMutableArray *sound;

int state1 = 0;



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(Nsstring *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically,without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view,typically from a nib.
- (void)viewDidLoad 
{
    list = [[NSMutableArray alloc] init];
    [list addobject:@\"A.png\"];
    [list addobject:@\"B.png\"];
    [list addobject:@\"C.png\"];
    [list addobject:@\"D.png\"];

    //[image1 setimage:[UIImage imageNamed:@\"A.png\"]];

    sound = [[NSMutableArray alloc] init];
    [sound addobject:@\"A.mp3\"];
    [sound addobject:@\"B.mp3\"];
    [sound addobject:@\"C.mp3\"];
    [sound addobject:@\"D.mp3\"];
    [sound addobject:@\"E.mp3\"];

    [super viewDidLoad];
}

-(IBAction) doNext
{
    int i,count;
    //state = 1;
    count = [list count];
    for(i = state1; i < count; i++)
    {
        [image1 setimage:[UIImage imageNamed:[list objectAtIndex:state1]]];

        //--------------------For Sound-----------------------------------

        //-----------------------------END--------------------------------


        //exit(0);

        //UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@\"hello\" message:[Nsstring stringWithFormat: @\"%d\",state1] delegate:self cancelButtonTitle:@\"ok\" otherButtonTitles:nil];
        //[alert show];
        state1 = state1 + 1;
        break;

    }
}

-(IBAction) doPrev
{
    int i,count;
    count = [list count];
    for(i = state1; i < count; i++)
    {
        state1 = state1 - 2;
        [image1 setimage:[UIImage imageNamed:[list objectAtIndex:state1]]];
        //UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@\"hello\" message:[Nsstring stringWithFormat: @\"%d\",state1] delegate:self cancelButtonTitle:@\"ok\" otherButtonTitles:nil];
        //[alert show];

        state1 = state1 + 1;
        break;

    }
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotatetoInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


- (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.
}

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


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

@end
很抱歉这个长问题。     

解决方法

        这是有关播放声音文件的出色教程: http://www.71squared.com/2009/05/iphone-game-programming-tutorial-9-sound-manager/ 解释清楚,代码是开源的!也很容易添加到任何项目中!     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?