googlevr / gvr-android-sdk

Google VR SDK for Android
http://developers.google.com/vr/android/
Other
3.28k stars 1.28k forks source link

VR Audio support for external file #193

Closed niusounds closed 8 years ago

niusounds commented 8 years ago

Hello,

createSoundfield(String filename) can only read audio from asset files in apk. I want to read external file! (somewhere in /sdcard/ like path) Is there a plan to add this feature?

JayaWei commented 8 years ago

I also have the same problem.

jkammerl commented 8 years ago

Loading sound files from the SD card should work. Please make sure that you add <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />` to your manifest and since Android N, you also need to trigger an intent to ask to user to grand external storage permission.

niusounds commented 8 years ago

I tried these codes

GvrAudioEngine audioEngine = new GvrAudioEngine(getContext(), GvrAudioEngine.RenderingMode.BINAURAL_HIGH_QUALITY);
final File file = new File(Environment.getExternalStorageDirectory(), "Ambi.wav");
int ambisonicId = audioEngine.createSoundfield(file.getAbsolutePath());

but ambisonicId is -1. I added <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> in AndroidManifest.xml. targetSdkVersion is 19.

I tried some methods, finally I found that these codes run successfully. (It plays strange distorted sound. But it may be other problem, not a bug in GVR library.)

GvrAudioEngine audioEngine = new GvrAudioEngine(getContext(), GvrAudioEngine.RenderingMode.BINAURAL_HIGH_QUALITY);
final File file = new File(Environment.getExternalStorageDirectory(), "Ambi.wav");
final String filename = file.getAbsolutePath();
audioEngine.preloadSoundFile(filename);
int ambisonicId = audioEngine.createSoundfield(file.getAbsolutePath());

API Document says Ambisonic soundfields do not need to be preloaded. I think it is not needed to call preloadSoundFile. Is it wrong?

niusounds commented 8 years ago

This issue will be the same topic with #197 so I close here.