在appdelegate中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions函数中添加如下代码,实现桌面背景和背景音乐
UIView *beview=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
//创建UIImage对象
UIImage *im=[UIImage imageNamed:@"456.jpg"];
beview.backgroundColor=[UIColor colorWithPatternImage:im];
// beview.backgroundColor=[UIColor brownColor];
// UIImage *im=[UIImage imageNamed:@"bar.png"];
[self.window addSubview:beview];
[beview release];
//播放声音
NSString *mp3Path=[[NSBundle mainBundle] pathForResource:@"Only One" ofType:@"mp3"];
//url分两种 一种是文件url(file) 一种是网络url(http://)
NSURL *url=[NSURL fileURLWithPath:mp3Path];
AVAudioPlayer *player=[[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
//设置循环次数
player.numberOfLoops=2;
// 告诉系统要播放音频
[player prepareToPlay];
[player play];
[self.window makeKeyAndVisible];
return YES;
}