Wie man MP3-Dateien von Parse.com abruft und wiedergibt
Ich entwickle eine App, mit der Sie einen Audioclip aufnehmen, in eine Datenbank auf Parse.com hochladen und dann den Audioclip von Parse.com abrufen und abspielen können.
Ich kann die Audiodatei auf Parse.com aufnehmen und hochladen, weiß aber nicht, was ich mit dem letzten Schritt tun soll! Hier können Sie sehen, wie ich den Audioclip auf Parse.com speichere und speichere
byte[] data = outputFile.getBytes();
//ParseUser currentUser = ParseUser.getCurrentUser();
//String usernameText = currentUser.getUsername();
Calendar c = Calendar.getInstance();
String mUploadName = c.get(Calendar.SECOND) + "_recording.mp3";
ParseFile file = new ParseFile(mUploadName, data);
file.saveInBackground();
// _PostStructure is the class where I've wrote the "set" and "get" methods to use the database on Parse.com
_PostStructure new_audiofile = new _PostStructure();
new_audiofile.setAudioFile(file);
new_audiofile.saveInBackground();
Und dies ist mein Versuch, den Audioclip von Parse.com abzurufen und abzuspielen
mediaPlayer = new MediaPlayer();
ParseQuery<ParseObject> query = ParseQuery.getQuery("MyClass");
query.getInBackground("jZAetQnISj", new GetCallback<ParseObject>() {
public void done(ParseObject recording, com.parse.ParseException e) {
if (e != null) {
//do nothing
}
else {
ParseFile audioFile = recording.getParseFile("AudioFile");
String audioFileURL = audioFile.getUrl();
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(audioFileURL);
mediaPlayer.prepare();
mediaPlayer.start();
text.setText("Recording Point: Playing");
finalTime = mediaPlayer.getDuration();
startTime = mediaPlayer.getCurrentPosition();
if(oneTimeOnly == 0){
seekbar.setMax((int) finalTime);
oneTimeOnly = 1;
}
endTimeField.setText(String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) finalTime)))
);
startTimeField.setText(String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime)))
);
seekbar.setProgress((int)startTime);
myHandler.postDelayed(UpdateSongTime,100);
pauseButton.setEnabled(true);
playButton.setEnabled(false);
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
Also, wenn ich einen Audioclip aufzeichne und auf Parse.com speichere, funktioniert alles einwandfrei. Wenn ich auf die Schaltfläche "Abspielen" tippe, stürzt die App nicht ab, es wird jedoch kein Ton abgespielt. Kannst du mir helfen, den Fehler zu finden?