Read audio file from device memory instead of Assets

Read audio file from device memory instead of Assets

android save file to internal storage
android save file to external storage example
how to access internal storage android
android read file from internal storage
how to get all audio files in android
android get internal storage path
android mediastore example

I am working with superpowered sdk for audio processing that excepts a file from assets using the following code.

AssetFileDescriptor fd0 = getResources().openRawResourceFd(R.raw.recorded_audio);
int fileAoffset = (int) fd0.getStartOffset(), fileAlength = (int) fd0.getLength();

The Above values passed to a function, as

SuperpoweredExample(Integer.parseInt(samplerateString), Integer.parseInt(buffersizeString), getPackageResourcePath(), fileAoffset, fileAlength);

This works fine and if i place my audio file in raw folder that works best, but my audio file generated at run time and read that we can't write files in assets. Is there any way i can use file from external memory location?

Just pass your file path as a string to the Superpowered open() method. No need for file offset and file length this time, as your file is a "full" file this time, not some part of a file. Perhaps you don't need Java for this at all.

Access media files from shared storage, Find all audio files on the primary external storage device. // On API <= 28, use VOLUME_EXTERNAL instead. val audioCollection = MediaStore.Audio.Media Asset Bundles pack those files together in an archive and the map is stored in the serialized data in an Asset Bundle object. Resources stores it’s map in a global singleton called the ResourceManager and the files themselves are just lose on disk.

Try this code,it is using MediaPlayer class.

package com.example.audiomediaplayer1;  

import android.os.Bundle;  
import android.view.Menu;  
import android.widget.MediaController;  
import android.widget.VideoView;  

public class MainActivity extends Activity {  

    protected void onCreate(Bundle savedInstanceState) {  

        MediaPlayer mp=new MediaPlayer();  
            mp.setDataSource("/sdcard/Music/maine.mp3");//Write your location here  

        }catch(Exception e){e.printStackTrace();}  


    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(, menu);  
        return true;  


or this one short and simple from external storage along with path.

String filePath = Environment.getExternalStorageDirectory()+"/yourfolderNAme/yopurfile.mp3";
    mediaPlayer = new  MediaPlayer();

hope it works for you.

Data and file storage overview, Use the directories within internal storage to save sensitive information that other apps Media, Shareable media files (images, audio files, videos), MediaStore API within your app's manifest file to install your app on external storage instead: for read-and-write access to external storage: READ_EXTERNAL_STORAGE  Not familiar with System.IO.FileStream but check if it needs to be opened in binary mode instead of text mode on Windows, if that's your OS. ALSO, when you go to read it in, check the byte count compared to the length when you wrote it to disk, and also compare that to the length of the created asset, see if there are any differences.

void SuperpoweredExample::setPlayerA(const char *path) {



Just send File path as a string.

Example "/sdcard/sample.mp3"

Audio File Services, This document describes Audio File Services, a C programming interface that enables you to read or write a wide variety of audio data to or from disk or a memory buffer. Gets information about an audio file property, including the size of the Consolidates audio data and performs other internal optimizations of the file  Play audio and video with MediaPlayer. 02/08/2017; 25 minutes to read +4; In this article. This article shows you how to play media in your Universal Windows app using the MediaPlayer class. With Windows 10, version 1607, significant improvements were made to the media playback APIs, including a simplified single-process design for background

1)in AndroidManifest.xml:

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

between package and application tags

2)create copy of Open File function in your .cpp file, without offset and length parameters:

extern "C" JNIEXPORT void
Java_com_superpowered_playerexample_MainActivity_OpenFile2 (
        JNIEnv *env,
        jobject __unused obj,
        jstring path      // path to APK file
        // length of audio file
) {
    const char *str = env->GetStringUTFChars(path, 0);
    player->open(str, 0, 0);
    env->ReleaseStringUTFChars(path, str);

3) in your MainActivity.class:

String file = "/mnt/shared/Other/more.mp3";

that works for me, hope this could help

Audio File Types – 5 Popular Options to Consider, Here are five popular audio file types and an in-depth explanation of each. of cloud storage and bigger hard drive space in contemporary computers. Music download software like Apple iTunes use M4A instead of MP3 because it's compatible with nearly every device capable of reading audio files. audio files + memory This research project looks at different formats of audio files, in particular the differences in how they are stored and read. Compression, sampling rates, bit depth, how they affect both the digital files and sound quality, are all explained.

Audio Files, Locomotion Based Blending · Copy a Pose from another Skeletal Mesh · Creating Dynamic Animations · Animation Pose Assets · Additive vs. Full Body. Because the actual paths to internal and external storage may vary from device to device or from Android version to Android version, it is not recommended to hard code the path to the files. Instead, use the Xamarin.Android APIs to determine the path to files.

Audio Overview, For playing media or audio files that are not simple, uncompressed audio, you can use the QMediaPlayer C++ In push mode, the audio device provides a QIODevice instance that can be written or read to as needed. Decoding Compressed Audio to Memory All other trademarks are property of their respective owners. Re: Write and read to device memory from user space This is covered in depth by the kernel driver literature. When doing a char driver (I assume that is what your driver is), you need to implement the read and write file-operations, or add support for mmap.

Manage files and apps on your Galaxy tablet, But if you accumulate too many files in your internal memory, you can save room by moving them to an external storage system, such as a microSD card or a cloud​  Adding audio clip to android application is a simple task as it also add some further functionality. Here is a step by step on how to play music when App will start. Adding Audio to app in Android Studio: Step 1: Open the android studio with the project in which you want to add-on audio clip/media file. Step 2: Create a raw folder.