-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.ts
More file actions
155 lines (133 loc) · 3.19 KB
/
common.ts
File metadata and controls
155 lines (133 loc) · 3.19 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as fs from 'tns-core-modules/file-system';
import { isString } from 'tns-core-modules/utils/types';
import { AudioPlayerOptions, AudioRecorderOptions } from './options';
export class TNSPlayerUtil {
public static debug: boolean = false;
}
export const TNS_Player_Log = (...args) => {
if (TNSPlayerUtil.debug) {
console.log('NativeScript-Audio - TNSPlayer', args);
}
};
export class TNSRecorderUtil {
public static debug: boolean = false;
}
export const TNS_Recorder_Log = (...args) => {
if (TNSRecorderUtil.debug) {
console.log('NativeScript-Audio - TNSRecorder', args);
}
};
export interface TNSPlayerI {
/**
* native instance getters
*/
readonly ios?: any;
readonly android?: any;
/**
* Volume getter/setter
*/
volume: any;
/**
* Starts playing audio file from local app files.
*/
playFromFile(options: AudioPlayerOptions): Promise<any>;
/**
* Starts playing audio file from url
*/
playFromUrl(options: AudioPlayerOptions): Promise<any>;
/**
* Play audio file.
*/
play(): Promise<boolean>;
/**
* Pauses playing audio file.
*/
pause(): Promise<boolean>;
/**
* Seeks to specific time.
*/
seekTo(time: number): Promise<boolean>;
/**
* Releases resources from the audio player.
*/
dispose(): Promise<boolean>;
/**
* Check if the audio is actively playing.
*/
isAudioPlaying(): boolean;
/**
* Get the duration of the audio file playing.
*/
getAudioTrackDuration(): Promise<string>;
/**
* current time
*/
readonly currentTime: number;
}
export interface TNSRecordI {
/**
* Starts the native audio recording control.
*/
start(options: AudioRecorderOptions): Promise<any>;
/**
* Pauses the native audio recording control.
*/
pause(): Promise<any>;
/**
* Resumes the native audio recording control.
*/
resume(): Promise<any>;
/**
* Stops the native audio recording control.
*/
stop(): Promise<any>;
/**
* Releases resources from the recorder.
*/
dispose(): Promise<any>;
}
/**
* Helper function to determine if string is a url.
* @param value [string]
*/
export function isStringUrl(value: string): boolean {
// check if artURL is a url or local file
let isURL = false;
if (value.indexOf('://') !== -1) {
if (value.indexOf('res://') === -1) {
isURL = true;
}
}
if (isURL === true) {
return true;
} else {
return false;
}
}
/**
* Will determine if a string is a url or a local path. If the string is a url it will return the url.
* If it is a local path, then the file-system module will return the file system path.
* @param path [string]
*/
export function resolveAudioFilePath(path: string) {
if (path) {
const isUrl = isStringUrl(path);
// if it's a url just return the audio file url
if (isUrl === true) {
return path;
} else {
let audioPath;
let fileName = isString(path) ? path.trim() : '';
if (fileName.indexOf('~/') === 0) {
fileName = fs.path.join(
fs.knownFolders.currentApp().path,
fileName.replace('~/', '')
);
audioPath = fileName;
} else {
audioPath = fileName;
}
return audioPath;
}
}
}