如何从Box Storage下载和播放Mp3文件

时间:2019-02-23 07:53:34

标签: android android-mediaplayer dropbox box

我正在完成我的最后一年的项目。我想从 Box Storage 下载和播放Mp3文件的地方,我有代码可以从 DropBox 播放文件,但是当我尝试从 Box Storage播放同一文件时无效。我想从仅用于Box Storage 中播放文件,目前我只能播放,我也想下载该文件。有人可以帮我吗?

预先感谢...!

以下是适用于 DropBox 的代码,但不适用于 Box Storage

Button b3 = rootView.findViewById(R.id.Play);
b3.setOnClickListener(new View.OnClickListener() {


        @Override
        public void onClick(View v) {
            final ProgressDialog mDialog = new ProgressDialog(getActivity());


            @SuppressLint("StaticFieldLeak") AsyncTask<String, String, String> mp3Play = new AsyncTask<String, String, String>() {

                @Override
                protected void onPreExecute() {
                    mDialog.setMessage("Please wait");
                    mDialog.show();
                    mDialog.setCancelable(false);
                }

                @Override
                protected String doInBackground(String... params) {
                    try {
                        mediaPlayer.setDataSource(params[0]);
                        mediaPlayer.prepare();
                    } catch (Exception ignored) {

                    }
                    return "";
                }

                @Override
                protected void onPostExecute(String s) {
                    mediaFileLength = mediaPlayer.getDuration();
                    realtimeLength = mediaFileLength;
                    if (!mediaPlayer.isPlaying()) {
                        p=1;
                        mediaPlayer.start();
                        Toast.makeText(getActivity(), "Playing sound", Toast.LENGTH_SHORT).show();
                        finalTime = mediaPlayer.getDuration();
                        startTime = mediaPlayer.getCurrentPosition();
                        b3.setBackgroundResource(R.drawable.pp);
                        if (oneTimeOnly == 0) {
                            oneTimeOnly = 1;
                        }
                    } else {
                        p=0;
                        mediaPlayer.pause();
                        Toast.makeText(getActivity(), "Pausing "+
                                "sound",Toast.LENGTH_SHORT).show();
                        b3.setBackgroundResource(R.drawable.p);
                    }

                    updateSeekBar();
                    mDialog.dismiss();
                }
            };

            mp3Play.execute(url); // link of mp3 file

        }
    });

0 个答案:

没有答案