Dynamically edit Uri for playing audio-files

All your problems with Audio, Video and Images.

Dynamically edit Uri for playing audio-files

Postby Danneman » Sun Oct 16, 2011 1:58 pm

I'm trying to play an mp3-file located in res/raw.

Problem is that I have a lot of audio that needs to be played dynamically.

This code does work for "mySound.mp3".

Code: Select all
mPlayer = MediaPlayer.create(main.this, R.raw.mySound);

Whereas this code does NOT work:

Code: Select all
String soundName = "mySound";
Uri uri_soundName = Uri.parse("R.raw." + soundName);
mPlayer = MediaPlayer.create(main.this, uri_soundName);

I've tried various other syntaxes to get the uri right, for instance:

Code: Select all
uri_soundName = Uri.parse("android.resource://com.myProject/myApp/raw/" + soundName);

...but to no avail.

Does anybody have an idea what I'm doing wrong?

Junior Developer
Junior Developer
Posts: 24
Joined: Thu Mar 26, 2009 12:42 pm


Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 12 guests