添加SubtitleUrl会杀死我的应用程序(ANR)

时间:2014-11-27 07:10:33

标签: android video-streaming android-videoview hls

嗨大家这可能听起来有点傻,但是当我正在加载一个hls流url到Android VideoView时,播放器开始流式传输视频就好了,但是当我添加字幕网址时,我寻求崩溃的应用程序崩溃,我对应用程序失去了完全控制权,视频流不会停止播放(即即使在后台也能继续播放)。

这就是我正在做的事情。(请帮我弄清楚我在做什么错误。提前谢谢)

mVideoView.setVideoURI(Uri.parse(mProfileUrl));
    mVideoView.setMediaController(new MediaController(this));
    if (null != mSubtitleUrl && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        new AddSubTitleAsync().execute(mSubtitleUrl);
    } 
}



//***************************************************************************

class AddSubTitleAsync extends AsyncTask<String, Void, InputStream> {
    ProgressDialog pd;

    @Override
    protected void onPreExecute() {
        // pd = ProgressDialog.show(mParentNotifier.getParentActivty(), "", "", false, false);
    }

    @SuppressLint("NewApi")
    @Override
    protected void onPostExecute(InputStream inputStream) {
        // if (pd != null && pd.isShowing())
        // pd.dismiss();

        if (null != inputStream) {
            mVideoView.addSubtitleSource(inputStream, MediaFormat.createSubtitleFormat("text/vtt", Locale.ENGLISH.getLanguage()));
        }
        // mParentNotifier.enableMainMenuLayout(false);
        mVideoView.requestFocus();
        // mVideoView.start();
        if (mMovieStartPoint > 0) {
            Timer mTimer = new Timer();
            mTimer.schedule(new TimerTask() {

                @Override
                public void run() {
                    mVideoView.seekTo(mMovieStartPoint);
                    mVideoView.start();
                }
            }, 5000);

            // mVideoView.seekTo(15 * 60 * 1000);
            // mVideoView.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    protected InputStream doInBackground(String... params) {
        InputStream inputStream = null;
        try {
            HttpHandler http = new HttpHandler();
            inputStream = http.getContent(params[0]);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return inputStream;
    }

}

0 个答案:

没有答案