android mediaplayer streaming FileNotFoundException没有内容提供者

时间:2016-10-02 17:26:34

标签: java android android-asynctask streaming android-mediaplayer

我的android.media.MediaPlayer抛出一个FileNotFoundException有时当它尝试prepareAsync()

时没有内容提供者

当我卷曲相同的命令时,文件会下载,我可以在桌面上播放。

所有文件都是3gpg格式。

当我尝试流式传输特定文件时。播放器适用于所有文件的80%,但对于大于2 mb的文件,我有时会遇到以下异常。

  

java.io.FileNotFoundException:没有内容提供者:   https://www.boom.com:443/api/mobile/1/getRecording/185/ at   android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1117)   在   android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:970)   在   android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:897)   在android.media.MediaPlayer.setDataSource(MediaPlayer.java:1112)at   com.killesk.boom.MediaPlayerAbstract.attachAudio(MediaPlayerAbstract.java:121)   在   com.killesk.boom.MediaPlayerAbstract.asyncGetActivityModelLatestDetailedRecordingsPostMethodScuess(MediaPlayerAbstract.java:451)   在   com.killesk.boom.network.asynctask.AsyncTaskGetActivityModelLatestDetailedRecordings.onPostExecute(AsyncTaskGetActivityModelLatestDetailedRecordings.java:94)   在   com.killesk.boom.network.asynctask.AsyncTaskGetActivityModelLatestDetailedRecordings.onPostExecute(AsyncTaskGetActivityModelLatestDetailedRecordings.java:34)   在android.os.AsyncTask.finish(AsyncTask.java:636)at   android.os.AsyncTask.access $ 500(AsyncTask.java:177)at   android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:653)   在android.os.Handler.dispatchMessage(Handler.java:102)at   android.os.Looper.loop(Looper.java:145)at   android.app.ActivityThread.main(ActivityThread.java:6934)at   java.lang.reflect.Method.invoke(Native Method)at   java.lang.reflect.Method.invoke(Method.java:372)at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1404)   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

我已检查过服务器上发生故障的文件,并且在我手动下载后它们播放完毕。差不多这是我的代码:

String url = AndroidPhoneProperties.REST_API +
                AndroidPhoneProperties.POST_GETRECORDING + File.separator +
                recordingServerID + File.separator;

        byte[] toEncrypt = (user.getEmail() + ":" + user.getPassword()).getBytes();
        String encoded = Base64.encodeToString(toEncrypt, Base64.DEFAULT);

        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "Basic " + encoded);

        Uri uri = Uri.parse(url);

        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        try {
            URL boom = new URL(url);
            URLConnection con = boom.openConnection();
            con.connect();
            con.getContent();
            Uri uriBoom = Uri.parse(con.getURL().toString());
            mediaPlayer.setDataSource(this, uriBoom, headers);
        } catch (IllegalArgumentException e) {
            showMessage("You might not set the URI correctly!");
        } catch (SecurityException e) {
            showMessage("You might not set the URI correctly!");
        } catch (IllegalStateException e) {
            showMessage("You might not set the URI correctly!");
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            mediaPlayer.prepareAsync();
        } catch (IllegalStateException e) {
            showMessage("You might not set the URI correctly!");
        }

        mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                enableView(true, play);
                play.setAlpha(AndroidPhoneProperties.ENABLED_ALPHA_RATE);
            }
        });

        mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                showMessage("Problem with the stream");
                return false;
            }
        });

        dismissDialog();

我有一种有趣的感觉,没有给它足够的时间开始蒸文件,但我不确定。有什么想法吗?

0 个答案:

没有答案