Code first:
InputStream is = ;//some mixed audio
byte buf[] = new byte[1024];
System.out.println(tempDir.getAbsolutePath());
File temp = File.createTempFile("aaa", ".mp3",
this.getCacheDir());
FileOutputStream out = new FileOutputStream(temp);
do {
int numread = is.read(buf);
if (numread <= 0)
break;
out.write(buf, 0, numread);
} while (true);
out.flush();
out.close();
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(temp.getAbsolutePath());
mp.prepare();
mp.start();
I want to make some audio fragments to one audio file, and
MediaPlayer could not play with byte or stream, so I have to use
tempfile.
upper code would: 11-05 05:47:37.512: WARN/System.err(3934):
java.io.IOException: Prepare failed.: status=0xFFFFFFFC.
But, if I copy the temp file aaa.mp3 out by File Explore, and copy
it into cache directory, the aaa.mp3 could be played.
The temp file created by app in linux is : -rw------- app_18
app_18 2868352 2008-11-05 03:54 aaa13710.mp3
The file copyed into cache is : -rw-rw-rw- root root
2868352 2008-11-05 04:20 aaa13710.mp3
The fiile copyed into sdcard is:----rw-rw- system system
2868352 2008-11-05 05:12 aaa13710.mp3
so, I guess MediaPlayer play audio files with root account.
Although creating temp file into sdcard is one solution, but i don't
think it is a good method for slow efficiency. MediaPlay should be
able to play with stream or byte, and it is a strange thing that I
could create an audio file but play it.
I saw other developers post this error, google wishes developer
create temp files into sdcard, in fact, creating temp file into sdcard
cann't solve anything.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---