简体   繁体   中英

Android media player error (-4 -4) for playing .ogg files from res/raw

Weird problem here.. Logcat is showing me this (-4 -4) error in my media player code. I have a file filename.ogg in the res/raw folder of my application and I'm trying to play it.

Here is the code:

 try {
                        String packageName = getPackageName(); 
                        int resID = getResources().getIdentifier( "filename" , "raw" , packageName );
                        mp.setDataSource("android.resource://" + packageName + "/" + resID);
                        mp.prepare();
                        mp.start();
                    } catch (Exception e) {
                        Toast.makeText(PlayScreen.this, e.toString(), Toast.LENGTH_LONG).show(); 
                    }

The toast message I see says:

java.io.IOException: Prepare failed.: status=0xFFFFFFFC

In eclipse logcat I see:

MediaPlayer Error (-4 -4)

Much thanks to anyone who can help with this... I just want to play my .ogg files from the res/raw folder.

int resID = getResources().getIdentifier( "filename" , "raw" , packageName );
                        mp.setDataSource("android.resource://" + packageName + "/" + resID);

instead of resID have you tried R.raw.youfilename

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM