如何在encryption的zip文件中传输音乐而不解压整个文件?

我必须播放audio文件。 这是在zip文件,这是目前在SD卡。 并且audio文件被encryption。 所以,当解密audio,我会得到inputstream中的数据。

我不想解压,因为它吃在磁盘上的空间。

正如我已经调查,我没有得到如何直接播放audio,如果我有stream的线索。 它只能通过networking。 这不是在这种情况下。

所以我想是产生一个线程,将保持附加数据(字节)的文件。 开始时,我打电话给MediadPlayer来开始工作。

媒体播放器没有问题。 乐趣从这里开始:假设audio文件在6min – 5MB。 缓冲可能已经发生了2MB。 在寻找酒吧,我可以看到2min作为我的最大持续时间。 这是完全正确的。 当缓冲还在继续时,我想更新search栏中的时间,其长度(search栏长度)与给定时间成正比。 我如何去做这件事。

我试过OnBufffering这个,它没有工作。 我想实际上它是用于stream式audio文件,如果它通过networking播放。

请给我一些简单的解决办法,如何做到这一点? 不要问我重写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); } }); } } 

Solutions Collecting From Web of "如何在encryption的zip文件中传输音乐而不解压整个文件?"

Afaik,你可以从zip压缩一个FileDescriptor,而不用使用Google的ZipResource Library解压,它只适用于扩展包,但是如果你只是存储这些项目而不是压缩它,那么它就可以完美工作(zip -r -n .mp3: .png:.txt命运起源)。

FileDescriptor已准备好与MediaPlayer一起使用,但是如果其encryption可能有两个描述符可能会帮助您优化解密stream。

 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”);

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