Describe the bug
I am trying to load a dynamic list of audios the user can record. Therefore I cannot "require" them and have to load them by name.
I have tried using a bundled file and I require that file, the file plays perfectly, when I try to load the same file using a file path it fails.
To Reproduce
Steps to reproduce the behavior:
This works
// Audiofile is file:///Users/pablo/Library/Developer/CoreSimulator/Devices/7F2A4DF9-9EBC-4C1C-9C1C-DA85C40DDA7F/data/Containers/Bundle/Application/EBCB2565-8496-4AFB-896B-5BBB8D0B898F/RosaryPro.app/audio/es/file.m4a
let audio = require(element.audioFile);
....
await this._audioPlayer.add({
id: element.audioFile,
url: audio,
title: 'none',
artist: 'none',
});
await this._audioPlayer.play();
This fails:
let audio = encodeURI(element.audioFile);
await this._audioPlayer.add({
id: audio,
url: audio,
title: 'none',
artist: 'none',
});
await this._audioPlayer.play();
Environment (please complete the following information):
System:
OS: macOS 10.15.6
CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
Memory: 20.79 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.16.3 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.8 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
Android SDK:
API Levels: 26, 27, 28, 29, 30
Build Tools: 27.0.3, 28.0.3, 29.0.2, 29.0.3, 30.0.1
System Images: android-28 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 12.0/12A7209 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_241 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
What react-native-track-player version are you using? 1.2.3
Are you testing on a real device or in the simulator? Simulator
Which OS version are you running? iOS 14
Code
// Audiofile is for example file:///Users/pablo/Library/Developer/CoreSimulator/Devices/7F2A4DF9-9EBC-4C1C-9C1C-DA85C40DDA7F/data/Containers/Bundle/Application/EBCB2565-8496-4AFB-896B-5BBB8D0B898F/RosaryPro.app/audio/es/file.m4a
let audio = encodeURI(element.audioFile);
await this._audioPlayer.add({
id: audio,
url: audio,
title: 'none',
artist: 'none',
});
await this._audioPlayer.play();
I found it. The problem is that version 1.2.3 has an error on Track.swift that is fixed on the Dev branch:
```:swift
func getSourceUrl() -> String {
return url.isLocal ? url.value.path : url.value.absoluteString
}
in version 1.2.3 is:
```:swift
func getSourceUrl() -> String {
return url.value.absoluteString
}
This prevents local files to be played.
Still having the same problem, you managed to solve this problem ?
I forked and fixed it in my repo... https://github.com/pabloromeu/react-native-track-player
But that's it.. I think nobody is maintaining this anymore
I see that this is a version for IOS, but I am having the same problem on Android, do you think it will work for Android too ?
@pabloromeu android is also facing same issue. Audio from local files are not playing. could you fix it too?
I just fixed the iOS part because the path was wrong. Sorry @sgc0014, It works for me on Android 🤷🏻♂️