gpt4 book ai didi

android - 如何在不解压缩整个文件的情况下从加密 zip 中的文件流式传输音乐?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:44:01 25 4
gpt4 key购买 nike

我必须播放音频文件。哪个在 zip 文件中,哪个存在于 sdcard 中。并且音频文件是加密的。因此,在解密音频时,我将获取输入流中的数据。

我不想解压缩,因为它会占用磁盘空间。

正如我所调查的,如果我有流媒体,我没有得到关于如何直接播放音频的线索。它只能通过网络。在这种情况下不是。

所以我的想法是生成一个线程,该线程将不断向文件追加数据(字节)。开始时,我调用 MediaadPlayer 开始它的工作。

媒体播放器运行良好。乐趣从这里开始:假设音频文件在 6 分钟 - 5MB 内。缓冲可能发生了 2MB。在搜索栏中,我可以看到 2 分钟是我的最长持续时间。这是完全正确的。当缓冲仍在继续..发生时,我想更新搜索栏中的时间及其长度(搜索栏长度)与给定时间成正比。我该怎么做。

我为此尝试了 OnBufffering,它没有用。我猜它实际上是用于流式音频文件,如果它通过网络播放的话。

请给我一些简单的解决方案,如何完成?不要让我覆盖 MediaPlayer 类并处理它。

感谢任何帮助。如果您需要更清楚地了解这一点,请告诉我。

public class NotesAudDisplay extends Activity implements OnPreparedListener, MediaController.MediaPlayerControl{
private static final String TAG = "activity-NotesAudioDisplay";

private String audioFilePath;
private String notesFileName;
private String mcfFileName;
private String key;

private SeekBar seekBarProgress;

private NotesElement notesElement = null;
private String notesTittle = "", notesHeading = "";
private TextView heading_tv, playerStatus_tv;
private QuesBuilder qb = null;

private MediaPlayer mediaPlayer = null;
private MediaController mediaController;

private Drawable play_butt, pause_butt;
private ProgressDialog pd;
private Resources res = null;

private Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audio_notesdisplay);

res = getResources();
play_butt = res.getDrawable(R.drawable.play);
pause_butt = res.getDrawable(R.drawable.pause);

heading_tv = (TextView) findViewById(R.id.notesHeading_tv);
playerStatus_tv = (TextView) findViewById(R.id.playerStatus_tv);

Intent intent = getIntent();
notesTittle = intent.getStringExtra("notesTittle");
notesFileName = intent.getStringExtra("notesFileName");
mcfFileName = intent.getStringExtra("mcfFileName");
key = intent.getStringExtra("key");

TextView tittle_tv = (TextView) findViewById(R.id.notesTittle_tv);
tittle_tv.setText(notesTittle);

NotesXMLParser nxp = new NotesXMLParser(this, notesFileName,
mcfFileName, key);
nxp.OpenXmlDocument();
notesElement = nxp.getNotesContent();
Log.d("TAG", "notesele:" + notesElement);
if (notesElement != null) {
notesHeading = notesElement.getHeading();
heading_tv.setText(notesHeading);

QuesBuilderSet qbs = notesElement.getNotesStatement();
ArrayList quesBuilder = qbs.getQuesBuilderSet();
if (quesBuilder != null) {
Log.d(TAG, " quesBuilder len:" + quesBuilder.size());
for (int i = 0; i < quesBuilder.size(); i++) {
qb = (QuesBuilder) quesBuilder.get(i);
if (qb.getType() == QuesBuilder.SPEECH) {
Log.d(TAG, " AUDIO");

String file = qb.getQuesSpeech();
File f = createTmpAudioFile(file);

boolean decrypt_result = false;
if (f != null) {
new LongOperation().execute(f);
Log.d(TAG,"****before long operation****");
try {
Log.d(TAG,"****before thread operation****");
Thread.sleep(3000);
Log.d(TAG,"****after thread operation****");
setContent();

} catch (Exception e) {
Log.d("InstructionForm", "Sleep thread fails");
}
Log.d(TAG,"****after catch****");
} else {
heading_tv.setText(notesHeading
+ " Unable to play the audio.");
}

} else {
Log.d(TAG, " other:" + qb.getType());
}
}
}
}
}// onCreate

public void setContent() {
mediaController = new MediaController(NotesAudDisplay.this);
mediaPlayer = new MediaPlayer();
Log.d(TAG,"***GOING TO PREP STATE***");
mediaPlayer.setOnPreparedListener(NotesAudDisplay.this);
Log.d(TAG,"***DONE WITH PREP STATE***");
try {
mediaPlayer.setDataSource(audioFilePath);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();
mediaPlayer.start();
playerStatus_tv.setText("Playing.. . ");
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

private File createTmpAudioFile(String file) {
DBAdapter dba = new DBAdapter(NotesAudDisplay.this);
dba.open();
String mobiDataPath = dba.get_mobidata_path();
dba.close();
audioFilePath = mobiDataPath + "/" + file;
Log.d(TAG, "tmp audio filePath:" + audioFilePath);
File f = null;
try {
f = new File(audioFilePath);
return f;
} catch (Exception e) {
f = null;
Log.d(TAG, " exception caught in creating audio file on sdcard");
}
return null;
}

private class LongOperation extends AsyncTask<File, Void, Boolean> {

@Override
protected void onPreExecute() {
// TODO run small wheel
// show_wheel();
}

@Override
protected Boolean doInBackground(File... arg0) {
DecryptZipReader dr = new DecryptZipReader();
File f = arg0[0];
Log.d(TAG, "*********copying start*********");
boolean res = dr.getDecryptFileStream(NotesAudDisplay.this,
qb.getQuesSpeech(), mcfFileName, key, f);
return new Boolean(res);
}

@Override
protected void onPostExecute(Boolean result) {
// close_wheel();
Log.d(TAG, "*********copying stop*********");

}

}

@Override
protected void onDestroy() {
super.onDestroy();
if (mediaPlayer != null) {
mediaPlayer.release();
mediaPlayer = null;
}

}

@Override
protected void onStop() {
super.onStop();
mediaPlayer.stop();
mediaPlayer.release();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
//the MediaController will hide after 3 seconds - tap the screen to make it appear again
mediaController.show(0);
return false;
}

//--MediaPlayerControl methods----------------------------------------------------
public void start() {
mediaPlayer.start();
}

public void pause() {
mediaPlayer.pause();
}

public int getDuration() {
Log.d(TAG,"***duration:"+mediaPlayer.getDuration());
return mediaPlayer.getDuration();
}

public int getCurrentPosition() {
return mediaPlayer.getCurrentPosition();
}

public void seekTo(int i) {
mediaPlayer.seekTo(i);
}

public boolean isPlaying() {
return mediaPlayer.isPlaying();
}

public int getBufferPercentage() {
return 0;
}

public boolean canPause() {
return true;
}

public boolean canSeekBackward() {
return true;
}

public boolean canSeekForward() {
return true;
}
//--------------------------------------------------------------------------------

public void onPrepared(MediaPlayer mediaPlayer) {
Log.d(TAG, "*********onPrepared*********");
mediaController.setMediaPlayer(this);
mediaController.setAnchorView(findViewById(R.id.main_audio_view));

handler.post(new Runnable() {
public void run() {
mediaController.setEnabled(true);
mediaController.show(0);
}
});
}
}

最佳答案

Afaik,您可以从 zip 中获取一个 FileDescriptor,而无需使用 Google 的 ZipResource 库进行解压,它仅用于扩展包,但如果您只是存储项目而不压缩它,它就可以完美地工作 (zip -r -n .mp3:.png:.txt 命运起源)。

FileDescriptor 已准备好与 MediaPlayer 一起使用,但如果它的加密可能有两个描述符可能会帮助您优化解密通量。

public ZipResourceFile getExpansionFiles(Context context){


ZipResourceFile expansionFile = null;
try {
expansionFile = new ZipResourceFile(
Environment.getExternalStorageDirectory() + "/MyFolder" + "/" + "/MyFile" + ".zip");

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}

然后使用:ZipResourceFile z = getExpansionFiles(mContext);

AssetFileDescriptor afd = z.getAssetFileDescriptor(mItem +".mp3");

我希望它有所帮助,无论如何,您确定不想等到文件完全解密,然后再播放它而不用担心所有这些即时的头痛吗?

关于android - 如何在不解压缩整个文件的情况下从加密 zip 中的文件流式传输音乐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8624504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com