summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLAudioFile.m
blob: 1d0e2ef98c009e31a4e0fe72dc215079ef17f4a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
//  SDLAudioFile.m
//  SmartDeviceLink-Example
//
//  Created by Joel Fischer on 10/24/17.
//  Copyright © 2017 smartdevicelink. All rights reserved.
//

#import "SDLAudioFile.h"

NS_ASSUME_NONNULL_BEGIN

@interface SDLAudioFile ()

@property (copy, nonatomic, readwrite) NSURL *inputFileURL;
@property (copy, nonatomic, readwrite) NSURL *outputFileURL;
@property (copy, nonatomic, readwrite) NSData *data;
@property (copy, nonatomic, readwrite) NSString *name;

@end

@implementation SDLAudioFile

- (instancetype)initWithInputFileURL:(NSURL *)inputURL outputFileURL:(NSURL *)outputURL estimatedDuration:(UInt32)duration {
    self = [super init];
    if (!self) { return nil; }

    _inputFileURL = inputURL;
    _outputFileURL = outputURL;
    _estimatedDuration = duration;

    return self;
}

- (NSData *)data {
    if (_data.length == 0) {
        return [NSData dataWithContentsOfURL:_outputFileURL];
    }

    return _data;
}

/**
 Gets the size of the data. The data may be stored on disk or it may already be in the application's memory.

 @return The size of the data.
 */
- (unsigned long long)fileSize {
    if (_outputFileURL != nil) {
        // Data in file
        NSString *path = [_outputFileURL path];
        return [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil].fileSize;
    } else if (_data) {
        // Data in memory
        return _data.length;
    }
    return 0;
}

@end

NS_ASSUME_NONNULL_END