Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NSCachesDirectory... #141

Merged
merged 1 commit into from Oct 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions ios/Classes/FlutterSoundPlugin.m
@@ -1,6 +1,11 @@
#import "FlutterSoundPlugin.h"
#import <AVFoundation/AVFoundation.h>

NSString* GetDirectoryOfType(NSSearchPathDirectory dir) {
NSArray* paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
return [paths.firstObject stringByAppendingString:@"/"];
}

@implementation FlutterSoundPlugin{
NSURL *audioFileURL;
AVAudioRecorder *audioRecorder;
Expand Down Expand Up @@ -181,9 +186,10 @@ - (void)setDbLevelEnabled:(BOOL)enabled result: (FlutterResult)result {

- (void)startRecorder :(NSString*)path :(NSNumber*)numChannels :(NSNumber*)sampleRate :(NSNumber*)iosQuality :(NSNumber*)bitRate result: (FlutterResult)result {
if ([path class] == [NSNull class]) {
audioFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:@"sound.m4a"]];

audioFileURL = [NSURL fileURLWithPath:[GetDirectoryOfType(NSCachesDirectory) stringByAppendingString:@"sound.m4a"]];
} else {
audioFileURL = [NSURL fileURLWithPath: [NSTemporaryDirectory() stringByAppendingString:path]];
audioFileURL = [NSURL fileURLWithPath: [GetDirectoryOfType(NSCachesDirectory) stringByAppendingString:path]];
}

NSMutableDictionary *audioSettings = [NSMutableDictionary dictionaryWithObjectsAndKeys:
Expand Down Expand Up @@ -246,7 +252,7 @@ - (void)stopRecorder:(FlutterResult)result {
- (void)startPlayer:(NSString*)path result: (FlutterResult)result {
bool isRemote = false;
if ([path class] == [NSNull class]) {
audioFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:@"sound.m4a"]];
audioFileURL = [NSURL fileURLWithPath:[GetDirectoryOfType(NSCachesDirectory) stringByAppendingString:@"sound.m4a"]];
} else {
NSURL *remoteUrl = [NSURL URLWithString:path];
if(remoteUrl && remoteUrl.scheme && remoteUrl.host){
Expand Down