0
我必須從FileInputStream中的原始文件夾指定mp3歌曲的路徑。實際上我有這個代碼(計算BPM)在Java和轉換成android。如何在原始文件夾中設置Android的FileInputStream中的路徑
package beatit;
import java.io.FileInputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javazoom.jl.player.Player;
/**
* @author Peter Backx
*/
public class Main {
static Logger log = Logger.getLogger("BeatIt");
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
BPM2SampleProcessor processor = new BPM2SampleProcessor();
processor.setSampleSize(1024);
EnergyOutputAudioDevice output = new EnergyOutputAudioDevice(processor);
output.setAverageLength(1024);
Player player = new Player(new FileInputStream(args[0]), output); // here i give mp3 from raw instead of arg[0].
player.play();
log.log(Level.INFO, "calculated BPM: " + processor.getBPM());
}
}
我試過如下:
Player player = new Player(new FileInputStream(R.raw.mh), output);
和,而不是球員,我用這個
MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.mh);
,但我遇到錯誤我的日誌貓文件
05-02 17:04:35.180: ERROR/AndroidRuntime(278): Caused by: java.lang.IndexOutOfBoundsException
05-02 17:04:35.180: ERROR/AndroidRuntime(278): at java.util.LinkedList.get(LinkedList.java:459)
05-02 17:04:35.180: ERROR/AndroidRuntime(278): at beatit.beatit.BPM2SampleProcessor.getBPM(BPM2SampleProcessor.java:69)
05-02 17:04:35.180: ERROR/AndroidRuntime(278): at beatit.beatit.Main.onCreate(Main.java:44)
05-02 17:04:35.180: ERROR/AndroidRuntime(278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-02 17:04:35.180: ERROR/AndroidRuntime(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-02 17:04:35.180: ERROR/AndroidRuntime(278): ... 11 more
如何讓它FileInputStream? – berserk 2014-12-04 09:18:51