AVAudioPlayer - अनुक्रम में एकाधिक ऑडियो फ़ाइलें खेल,

वोट
5

मैं AVAudioPlayer का उपयोग कर,, कई एमपी 3 फ़ाइलें खेलने के लिए अनुक्रम (एक के बाद एक) में चाहते हैं। मैं इसे करने की कोशिश की, और यह पहली एमपी 3 खेलने के बाद बंद हो जाता है। हालांकि, अगर मैं डिबगर में जाते हैं, यह ठीक काम करता है .. किसी भी विचार? मैंने कहीं AVAudioPlayer पृष्ठभूमि में बजता ऑडियो पढ़ा .. मैं इसे कैसे ऐसा करने से रोक सकता हूँ? वास

07/03/2009 को 03:29
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


5 जवाब

वोट
10

मुझे लगता है कि AVQueuePlayer(के उपवर्ग AVPlayer) वास्तव में यह काम (मदों की एक अनुक्रम खेलने) करता है आईओएस 4.1 के बाद से: http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVQueuePlayer_Class/Reference/Reference.html

मैं इसे अपने आप फिर भी कोशिश नहीं की लेकिन निश्चित रूप से इसे करने के लिए एक कोशिश दे देंगे।

23/08/2012 को 12:39
का स्रोत उपयोगकर्ता

वोट
3

खैर, अपने कोड उदाहरण मेरे लिए बॉक्स से बाहर काम नहीं किया। Soooo, मैं सोचा मैं एक निश्चित संस्करण के साथ जवाब चाहते हैं:

Looper.h:

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

@interface Looper : NSObject <AVAudioPlayerDelegate> {
    AVAudioPlayer* player;
    NSArray* fileNameQueue;
    int index;
}

@property (nonatomic, retain) AVAudioPlayer* player;
@property (nonatomic, retain) NSArray* fileNameQueue;

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

@end

Looper.m:

#import "Looper.h"
@implementation Looper
@synthesize player, fileNameQueue;

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

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

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

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

- (void)dealloc {
    self.fileNameQueue = nil;
    self.player = nil;        
    [super dealloc];
}

@end

और यहाँ मैं इसे कैसे कहेंगे है:

 Looper * looper = [[Looper alloc] initWithFileNameQueue:[NSArray arrayWithObjects: audioFile, audioFile2, nil ]];

मैं केवल का उपयोग कर ऑब्जेक्टिव-सी तो अतिरिक्त आलोचना के साथ बेझिझक जवाब iPhone / iPad के विकास के साथ अनुभव के एक वर्ष से अधिक से थोड़ा है।

09/04/2012 को 21:21
का स्रोत उपयोगकर्ता

वोट
3

ध्वनि प्रति एक AVAudioPlayer का प्रयोग करें।

02/08/2009 को 16:51
का स्रोत उपयोगकर्ता

वोट
1

यह एक अच्छा विचार viewDidLoad विधि पर, प्रारंभ करने में आइटम तैयार करना, और समय से आगे कतार, उदाहरण के लिए है।

आप स्विफ्ट पर काम कर रहे हैं, तो

    override func viewDidLoad() {
        super.viewDidLoad()
        let item0 = AVPlayerItem.init(URL: NSBundle.mainBundle().URLForResource("url", withExtension: "wav")!)

        let item1 = AVPlayerItem.init(URL: NSBundle.mainBundle().URLForResource("dog", withExtension: "aifc")!)
        let item2 = AVPlayerItem.init(URL: NSBundle.mainBundle().URLForResource("GreatJob", withExtension: "wav")!)


        let itemsToPlay:[AVPlayerItem] = [item0, item1, item2] 
        queuePlayer = AVQueuePlayer.init(items: itemsToPlay)
    }

और फिर जब कोई घटना होती है,

 queuePlayer.play()

ध्यान दें कि यदि आप कतार उपयोग करते हैं, तो आप अभी भी ध्वनियों के बीच कुछ अंतराल हो सकता है।

आपको विचाराधीन ऑब्जेक्टिव-सी संस्करण पा सकते हैं जब AVQueuePlayer पिछले playeritem खत्म कुछ करने के लिए कैसे

आशा करता हूँ की ये काम करेगा।

29/04/2016 को 09:35
का स्रोत उपयोगकर्ता

वोट
1

मैं इस संभाल करने के लिए एक वर्ग क्रियान्वित किया है।

सिर्फ इस तरह से कुछ करने का उपयोग करें:

[looper playAudioFiles:[NSArray arrayWithObjects:
    @"add.mp3",
    [NSString stringWithFormat:@"%d.mp3", numeral1.tag],
    @"and.mp3",
    [NSString stringWithFormat:@"%d.mp3", numeral2.tag],
    nil
]];

Looper.m

#import "Looper.h"
@implementation Looper
@synthesize player, fileNameQueue;

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

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

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

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

- (void)dealloc {
    self.fileNameQueue = nil;
    self.player = nil;        
    [super dealloc];
}

@end

Looper.h

#import <Foundation/Foundation.h>


@interface Looper : NSObject <AVAudioPlayerDelegate> {
    AVAudioPlayer* player;
    NSArray* fileNameQueue;
    int index;
}

@property (nonatomic, retain) AVAudioPlayer* player;
@property (nonatomic, retain) NSArray* fileNameQueue;

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


@end
20/07/2011 को 06:58
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more