简体   繁体   中英

want to create an app with .amr audio format file in swift

Hello I want to create an audio player app, which contains around 250 songs. App must work offline. So, i tried to use .aac and .mp3 format for audio but the size of the app increased to around 300Mb .

Now I want want to use .amr format but the simulator does not work with the .amr format. Need suggestion.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    playList = [
        URL(fileURLWithPath:Bundle.main.path(forResource: "vpn01", ofType: "aac")!),
        URL(fileURLWithPath:Bundle.main.path(forResource: "vpn02", ofType: "aac")!),
        URL(fileURLWithPath:Bundle.main.path(forResource: "vpn01", ofType: "aac")!),
        URL(fileURLWithPath:Bundle.main.path(forResource: "vpn04", ofType: "aac")!),
        URL(fileURLWithPath:Bundle.main.path(forResource: "vpn05", ofType: "aac")!),
        URL(fileURLWithPath:Bundle.main.path(forResource: "vpn06", ofType: "aac")!),
        URL(fileURLWithPath:Bundle.main.path(forResource: "vpn07", ofType: "aac")!)]
Check the following points:

AMR is no longer supported (for ≥ iOS 4.3, see supported audio formats in the Apple iOS SDK Documentation). Do you want to use the AVPlayer (audio and video) or do you want audio only? Use for Audio only the AVAudioPlayer. The following code snippet shows how to handle it. If you want to use AVAudioPlayer, does your self instance implement the AVAudioPlayerDelegate Protocol? Does your self instance implement the AVAudioPlayerDelegate Protocol? Have you added and linked correctly the AVAudioFoundation framework (#import )?

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"audio" ofType:@"m4a"]];

    NSError *error = noErr;
    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    if (error)
    {
        NSLog(@"Error in audioPlayer: %@", [error localizedDescription]);
    }
    else 
    {
        self.audioPlayer.delegate = self;
        [self.audioPlayer prepareToPlay];
    }
}

- (void)playAudio
{
    [self.audioPlayer play];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM