Organizational Research By

Surprising Reserch Topic

boostr.in questions - Question:play an audio file from jar resource with android


if I have this method in a jar library:

public void playAudioFile()
{
  ClassLoader cLoader = getClass().getClassLoader();
  URL url = cLoader.getResource("audio.mp3"); // in the resource of the jar library
  System.out.println(url.toString());

  MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setDataSource(url);
}

After compiling the library, I have: MySDK.jar

When I add the MySDK.jar into my android application and try to play an audio file:

private void playAudio()
{
   MySDK.Audio audio = new MySDK.Audio();
   audio.playAudioFile();
}

After compiling the android application, I have: mysampleapp.apk

When debugging the application, the audio file can't be played because:

System.out.println(url.toString());

gives:

jar:file:/data/app/com.mysampleapp.apk!/audio.mp3

The path of the audio should be from the jar file not from the sample app. Therefore, the audio file can not be played.

What did I do wrong and how can I play an audio file as a resource file from the jar library?

Thanks in advance.

 

asked Sep 13, 2013 in ANDROID by android_master
edited Sep 12, 2013
0 votes
14 views



Related Hot Questions



Government Jobs Opening


...