나는 안드로이드 응용 프로그램을 사용하여 캐시 디렉토리에 동적으로 midi 파일을 생성합니다.Android MediaPlayer는 설치시 파일이 필요합니다.
생성 후 동일한 앱 내에서 MediaPlayer로 파일을 재생합니다.
앱을 처음 실행할 때 이미 캐시 디렉토리에 파일이 있어야합니다 (앱이 다운 됨). 파일 관리자를 사용하여 더미 파일을 먼저 배치하면 에뮬레이터에서 작동합니다. 어떻게 이것을 피할 수 있습니까?
파일을 필요로하지 않고 처음으로 태블릿에서 실행하려면 앱이 필요합니다.
지금 이러한 명령을 사용하고 있습니다 :
try {
filePath = getCacheDir() + "/optimuse" + song + ".mid";
file = new File(filePath);
inputStream = new FileInputStream(file);
if (inputStream.getFD().valid()) {
System.out.println("Valid!");
}
} catch (Exception e1) {
e1.printStackTrace();
System.exit(-1);
}
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(inputStream.getFD());
inputStream.close();
} catch (Exception e1) {
e1.printStackTrace();
System.exit(-1);
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
이 주변에 어떤 방법이 있나요?
감사합니다.
고마워요! 방금 제 3 행 다음에 if (file.exists()) {를 추가했습니다. – dorien