次回にインターネットに接続しないでDropboxからオーディオファイルをダウンロードしようとしていますので、コードは実際にファイルをダウンロードしますが、私がダウンロードしたファイルか何かを解析する必要があれば、私は知らない、あなたはAndroidがmp3ファイルをダウンロードして再生する
ファイルのダウンロードを支援し、クラス、それを再生することを願って、それが実行ポストにそれを再生したり、少なくともそれが
class DownloadFileFromURL extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Bar Dialog
*/
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
/**
* Downloading file in background thread
*/
@Override
protected String doInBackground(String... f_url) {
int count;
try {
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
// this will be useful so that you can show a tipical 0-100%
// progress bar
int lenghtOfFile = conection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url.openStream(),
8192);
// Output stream
OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory().getPath()+"/workout.mp3");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress("" + (int) ((total * 100)/lenghtOfFile));
// writing data to file
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
}
/**
* Updating progress bar
*/
protected void onProgressUpdate(String... progress) {
// setting progress percentage
pDialog.setProgress(Integer.parseInt(progress[0]));
}
/**
* After completing background task Dismiss the progress dialog
**/
@Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);
Uri u = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/workout.mp3");
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(Environment.getExternalStorageDirectory().getPath()+"/workout.mp3");
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}
}
をしようとします
実際にこのエラーがログに記録される
05-31 11:46:11.605 4638-4650/com.example.project.calisthenic E/MediaPlayer: error (1, -2147483648)
問題は、アンドロイドのネイティブプレーヤーで再生しようとしても、「このタイプのオーディオファイルはサポートしていません」というようにダウンロードしたファイルを再生しようとしているため、誤った方法でファイルをダウンロードしているo間違った方法で再生しようとしている。
私はチェックしたいとファイルサイズが10キロバイトで、ダウンロードした後、それは400Bはそう間違いなく問題はそこから来た場合、私は知りませんが、あなたが準備しなければならないダウンロード
あなたはどのような問題に直面していますか?エラーが発生した場合は、ログを投稿してください。 – RAAAAM