从服务器播放一些mp4文件导致我异常

时间:2016-06-13 10:04:10

标签: android video-streaming mp4 android-videoview

我想将视频文件从服务器流式传输到VideoView但它会导致问题

videoView=(VideoView)findViewById(R.id.myvideo);
    Uri uri=Uri.parse("http://travel.gockell.com/data/251/videos/2016-06-09_13-21-12.mp4");

    videoView.setVideoURI(uri);

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            videoView.start();
        }
    });

错误

  

D / MediaPlayer:setDataSource IOException发生:                                                                                                java.io.FileNotFoundException:没有内容提供者:   http://travel.gockell.com/data/251/videos/2016-06-09_13-21-12.mp4                                                                                                    在   android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1070)                                                                                                    在   android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:925)                                                                                                    在   android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:852)                                                                                                    在android.media.MediaPlayer.setDataSource(MediaPlayer.java:1094)                                                                                                    在android.widget.VideoView.openVideo(VideoView.java:372)                                                                                                    在android.widget.VideoView.access $ 2100(VideoView.java:73)                                                                                                    在android.widget.VideoView $ 7.surfaceCreated(VideoView.java:649)                                                                                                    在android.view.SurfaceView.updateWindow(SurfaceView.java:599)                                                                                                    在android.view.SurfaceView $ 3.onPreDraw(SurfaceView.java:181)                                                                                                    在   android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)                                                                                                    在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982)                                                                                                    在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1062)                                                                                                    在   android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5873)                                                                                                    在   android.view.Choreographer $ CallbackRecord.run(Choreographer.java:767)                                                                                                    在android.view.Choreographer.doCallbacks(Choreographer.java:580)                                                                                                    在android.view.Choreographer.doFrame(Choreographer.java:550)                                                                                                    在   android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:753)                                                                                                    在android.os.Handler.handleCallback(Handler.java:739)                                                                                                    在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                                    在android.os.Looper.loop(Looper.java:135)                                                                                                    在android.app.ActivityThread.main(ActivityThread.java:5536)                                                                                                    at java.lang.reflect.Method.invoke(Native Method)                                                                                                    在java.lang.reflect.Method.invoke(Method.java:372)                                                                                                    在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1397)                                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)06-13   14:57:01.734   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   D / MediaPlayer:无法在客户端打开文件,尝试服务器端   06-13 14:57:01.764   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer:setVideoSurfaceTexture 06-13 14:57:01.764   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer-JNI:setAudioStreamType:3 06-13 14:57:01.764   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer:MediaPlayer :: setAudioStreamType 06-13 14:57:01.764   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer:setVideoSurfaceTexture 06-13 14:57:01.764   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer:prepareAsync 06-13 14:57:01.794   16590-16610 / videoplayer.dreamdeveloper.com.livevideoplayer   D / MediaHTTPConnection:filterOutInternalHeaders:key = User-Agent,val =   stagefright / 1.2(Linux; Android 5.0.2)06-13 14:57:01.874   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer I /时间线:   时间轴:Activity_idle id:android.os.BinderProxy@114c03a5   时间:57014665 06-13 14:57:01.944   16590-16605 / videoplayer.dreamdeveloper.com.livevideoplayer   I / System.out:(HTTPLog)-Static:SBServiceAPI:getService类   android.os.ServiceManager 06-13 14:57:01.944   16590-16605 / videoplayer.dreamdeveloper.com.livevideoplayer   I / System.out:(HTTPLog)-Static:isSBSettingEnabled false 06-13   14:57:01.944   16590-16605 / videoplayer.dreamdeveloper.com.livevideoplayer   I / System.out:(HTTPLog)-Static:isShipBuild true 06-13 14:57:01.944   16590-16605 / videoplayer.dreamdeveloper.com.livevideoplayer   I / System.out:(HTTPLog)-Thread-40119-261283142:SmartBonding启用   如果为假,SHIP_BUILD为true,则log to file为false,DBG为false 06-13   14:57:01.944   16590-16605 / videoplayer.dreamdeveloper.com.livevideoplayer   I / System.out:(HTTPLog)-Static:isSBSettingEnabled false 06-13   14:57:03.314   16590-16605 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaHTTPConnection:mTotalSize是-1 06-13 14:57:03.324   16590-16610 / videoplayer.dreamdeveloper.com.livevideoplayer   D / MediaHTTPConnection:setReadTimeOut = 30000ms 06-13 14:57:05.814   16590-18648 / videoplayer.dreamdeveloper.com.livevideoplayer   D / MediaHTTPConnection:setReadTimeout with 30000ms 06-13 14:57:05.814   16590-18648 / videoplayer.dreamdeveloper.com.livevideoplayer   I / System.out:(HTTPLog)-Static:isSBSettingEnabled false 06-13   14:57:06.494   16590-18648 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaHTTPConnection:mTotalSize是-1 06-13 14:57:06.494   16590-18648 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaHTTPConnection:服务器不支持部分请求06-13   14:57:06.494   16590-18648 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaHTTPConnection:返回-EPIPE 06-13 14:57:06.494   16590-16610 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer:消息收到msg = 100,ext1 = 1,ext2 = -2147483648   06-13 14:57:06.494   16590-16610 / videoplayer.dreamdeveloper.com.livevideoplayer   E / MediaPlayer:错误(1,-2147483648)06-13 14:57:06.494   16590-16610 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer:回调应用程序06-13 14:57:06.494   16590-16610 / videoplayer.dreamdeveloper.com.livevideoplayer   V / MediaPlayer:回调06-13 14:57:06.504   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   E / MediaPlayer:错误(1,-2147483648)06-13 14:57:06.504   16590-16590 / videoplayer.dreamdeveloper.com.livevideoplayer   D / VideoView:错误:1,-2147483648

3 个答案:

答案 0 :(得分:0)

请试试这个:

String VideoURL = "http://travel.gockell.com/data/251/videos/2016-06-09_13-21-12.mp4";

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

videoview = (VideoView) findViewById(R.id.VideoView);

try {
    // Start the MediaController
    MediaController mediacontroller = new MediaController(
                VideoViewActivity.this);
    mediacontroller.setAnchorView(videoview);
    // Get the URL from String VideoURL
    Uri video = Uri.parse(VideoURL);
    videoview.setMediaController(mediacontroller);
    videoview.setVideoURI(video);

} catch (Exception e) {
    Log.e("Error", e.getMessage());
    e.printStackTrace();
}

videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() {
    // Close the progress bar and play the video
    public void onPrepared(MediaPlayer mp) {

            videoview.start();
    }
});

}

答案 1 :(得分:0)

这个正在为我工​​作

videoview = (VideoView) findViewById(R.id.VideoView);
try {
    // Start the MediaController
    final MediaController mediacontroller = new MediaController(
            BioskopFilmDetail.this);
    mediacontroller.setAnchorView(videoview);
    // Get the URL from String VideoURL
    Uri video = Uri.parse(URLVIDEO );
    videoview.setMediaController(new MediaController(this){
        public boolean dispatchKeyEvent(KeyEvent event)
        {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP)
                ((Activity) getContext()).finish();                 
            return super.dispatchKeyEvent(event);
        }
    });
    videoview.setVideoURI(video);
} catch (Exception e) {
    Log.e("Error", e.getMessage());
    e.printStackTrace();
}
videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() {
    // Close the progress bar and play the video
    public void onPrepared(MediaPlayer mp) {                
        videoview.start();
        //showInterstitialAd();
    }
});

不要忘记在清单

中添加<uses-permission android:name="android.permission.INTERNET"/>

答案 2 :(得分:0)

感谢帮助每个人的所有代码都很好没有代码问题,但问题是在模拟器有时它播放,有些时候不是。在真实设备上工作。