MCPcopy Create free account
hub / github.com/zmxv/react-native-sound / constructor

Method constructor

src/index.ts:68–119  ·  view source on GitHub ↗
(
    filename: string,
    basePath?: string | ((error: string, props: SoundProps) => void),
    onError?: (error: string, props: SoundProps) => void,
    options?: SoundOptionTypes
  )

Source from the content-addressed store, hash-verified

66 private onPlaySubscription: EmitterSubscription;
67
68 constructor(
69 filename: string,
70 basePath?: string | ((error: string, props: SoundProps) => void),
71 onError?: (error: string, props: SoundProps) => void,
72 options?: SoundOptionTypes
73 ) {
74 if (filename.startsWith("http")) {
75 this._filename = filename;
76 } else {
77 this._filename = basePath ? `${basePath}/${filename}` : filename;
78
79 if (IsAndroid && !basePath && isRelativePath(filename)) {
80 this._filename = filename.toLowerCase().replace(/\.[^.]+$/, "");
81 }
82 }
83
84 if (typeof basePath === "function") {
85 onError = basePath;
86 }
87
88 this._key = nextKey++;
89 this._loaded = false;
90 this._playing = false;
91 this._duration = -1;
92 this._numberOfChannels = -1;
93 this._volume = 1;
94 this._pan = 0;
95 this._numberOfLoops = 0;
96 this._speed = 1;
97 this._pitch = 1;
98
99 RNSound.prepare(
100 this._filename,
101 this._key,
102 options ?? {},
103 (error: string, props: SoundProps) => {
104 if (props) {
105 if (typeof props.duration === "number") {
106 this._duration = props.duration;
107 }
108 if (typeof props.numberOfChannels === "number") {
109 this._numberOfChannels = props.numberOfChannels;
110 }
111 }
112 if (error === null) {
113 this._loaded = true;
114 this.registerOnPlay();
115 }
116 onError && onError(error, props);
117 }
118 );
119 }
120
121 private registerOnPlay() {
122 if (this.onPlaySubscription) {

Callers

nothing calls this directly

Calls 2

registerOnPlayMethod · 0.95
isRelativePathFunction · 0.85

Tested by

no test coverage detected