gpt4 book ai didi

iphone - 一起播放 .mp3 文件的两个循环

转载 作者:行者123 更新时间:2023-11-29 13:18:05 31 4
gpt4 key购买 nike

有没有办法在iphone sdk中同时播放2个声音文件循环

感谢和问候什维塔

最佳答案

    #import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface MultiAVPlay : NSObject <AVAudioPlayerDelegate> {
AVAudioPlayer* myplayer;
NSArray* fileNames;
int ind;
}

@property (nonatomic, retain) AVAudioPlayer* myplayer;
@property (nonatomic, retain) NSArray* fileNames;

- (id)initWithFileNameQueue:(NSArray*)names;
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag;
- (void)play:(int)i;
- (void)stop;

@end


#import "MultiAVPlay.h"
@implementation MultiAVPlay
@synthesize myplayer, fileNames;

- (id)initWithFileNameQueue:(NSArray*)files {
if ((self = [super init])) {
self.fileNames = files;
index = 0;
[self play:index];
}
return self;
}

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
if (index < fileNames.count) {
[self playMp3:index];
} else {
//reached end of queue
}
}

- (void)playMp3:(int)i {
self.myplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:[fileNames objectAtIndex:i] ofType:nil]] error:nil];
[myplayer release];
myplayer.delegate = self;
[myplayer prepareToPlay];
[myplayer play];
index++;
}

- (void)stop {
if (self.myplayer.playing) [myplayer stop];
}

- (void)dealloc {
self.filenames = nil;
self.myplayer = nil;
[super dealloc];
}

@end

关于iphone - 一起播放 .mp3 文件的两个循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15132085/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com