我想知道在浏览器中加载的Base64 DataURL图像的最大长度是多少?
谢谢!
我正在开发一个能播放mp3文件的Android应用程序.但是mp3文件是在SD卡或sqlite上加密的.无论哪种方式,在解密之后,我都会有一个字节流.我怎么玩他们?MediaPlayer不将输入流作为参数,因此我无法考虑这一点.
我有byte []数组,其中包含mp3文件。有什么方法可以在不创建临时文件的情况下播放mp3文件?
谢谢
编辑:
我尝试了临时文件方法:
File tempMp3 = File.createTempFile("test", ".mp3", getCacheDir());
//tempMp3.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempMp3);
fos.write(bytes);
fos.close();
mediaPlayer = MediaPlayer.create(getApplicationContext(),Uri.fromFile(tempMp3));
mediaPlayer.start();
Run Code Online (Sandbox Code Playgroud)
而且我仍然收到NullPointerException。我正在将字节数组(称为字节)写入文件,我保持其引用并使用它。但仍然获得NPE。你知道错在哪里吗?
我正在尝试使用MediaPlayer播放音频文件.我想在MediaPlayer中播放字节数组.我怎样才能做到这一点?我检查过这个
public void writeSamples(byte[] samples, int length)
{
// track.write( samples, 0, length);
File tempMp3;
try {
tempMp3 = File.createTempFile("kurchina", ".mp3");
tempMp3.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempMp3);
fos.write(samples);
fos.close();
// Tried reusing instance of media player
// but that resulted in system crashes...
MediaPlayer mediaPlayer = new MediaPlayer();
// Tried passing path directly, but kept getting
// "Prepare failed.: status=0x1"
// so using file descriptor instead
FileInputStream fis = new FileInputStream(tempMp3);
mediaPlayer.setDataSource(fis.getFD());
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IOException e) { …Run Code Online (Sandbox Code Playgroud) 我的数据库有很多简短的音频,这些音频格式化了base64。我要在单击按钮时播放音频。基本上,我写了这段代码,但是它不起作用。(如果可能,最好不要将文件写入存储,因为此过程会有延迟)
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
String url = "data:audio/mp3;base64,"+base64FormattedString;
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
}
catch(Exception e){
e.printStackTrace();
}
}
});
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪在这里:https : //gist.github.com/AliAtes/aa46261aba3d755fbbd1eba300356a5f
我想从缓冲区播放音频.比如使用AudioRecord将音频录制到缓冲区并从缓冲区播放.
有办法吗?在MediaPlayer中没有这样的选项.