Воспроизвести ресурс MP3

Я хочу создать приложение, похожее на iPod, которое будет воспроизводить только файлы MP3, которые у меня есть в папке ресурсов проекта.

Каким образом я должен это сделать?


person YogevSitton    schedule 11.08.2012    source источник
comment
Это может быть полезно: stackoverflow.com/questions/9625155/playing- mp3-из-nsbundle   -  person John Carter    schedule 11.08.2012
comment
Я проверю - спасибо!   -  person YogevSitton    schedule 11.08.2012


Ответы (2)


.h файл

#include <AVFoundation/AVFoundation.h>
@interface audioplayer : NSObject 
<AVAudioPlayerDelegate>
{
    NSTimer * timer;
    AVAudioPlayer * audio;
}
@end

.м файл

// start plying music
@implementation audioplayer
- (void)main 
{
    [super viewDidLoad];
    NSString * path = [[NSBundle mainBundle] pathForResource:@"soundfile" ofType:@"mp3"];
    NSURL * url = [NSURL fileURLWithPath:path];
    audio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    audio.delegate = self;
    [audio play];
    timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(playSequence) userInfo:nil repeats:YES];
    
}
// display the time playing
- (void) playSequence{
    if(audio.playing){
        NSLog(@"%@", [NSString stringWithFormat:@"%f", audio.currentTime]);
    } else {
        [timer invalidate];
    }    
}
@end
person Feel Physics    schedule 11.08.2012
comment
Отлично работает - спасибо. Как я могу получить данные трека, например, исполнителя и название? - person YogevSitton; 11.08.2012