0
我正在構建一個android應用程序。如果它存在於我的/ res/raw文件夾中,我只想播放一個wav文件。下面的代碼不起作用,因爲f.exists()總是計算爲false:Android無法在我的res/raw文件夾中播放wav文件
String filePathString = "android.resource://"+_context.getPackageName()+"/res/raw/oldphone_mono.wav";
File f = new File(filePathString);
java.io.InputStream inputStream = _context.getResources().openRawResource(com.hello20.R.raw.oldphone_mono);
if(f.exists()) {
Uri ringUri = Uri.parse(filePathString);
_ring = new MediaPlayer();
_ring.setDataSource(_context, ringUri);
final AudioManager audioManager = (AudioManager) _context.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_RING) != 0) {
_ring.setAudioStreamType(AudioManager.STREAM_RING);
_ring.setLooping(true);
_ring.prepare();
_ring.start();
}
我還應該做些什麼才能使其工作?
完美塔tworked – John