簡體   English   中英

如何從URL流式傳輸實時視頻?

[英]How to stream a live video from a URL?

我想將此鏈接嵌入到我的android應用程序中。 我嘗試這樣做,但是視頻無法加載。 我還收到錯誤java.io.FileNotFoundException:沒有內容提供者:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_cctv, container, false);

    try {
        String cctv = "http://121.58.202.110:8080/jpeg?cam=4";
        VideoView videoView = getView().findViewById(R.id.cctvfragment);
        MediaController mediaController = new MediaController(getActivity());
        mediaController.setAnchorView(videoView);
        Uri video = Uri.parse(cctv);
        videoView.setMediaController(null);
        videoView.setVideoURI(video);
        videoView.start();
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {

            }
        });
    } catch (Exception e) {
        // TODO: handle exception
        Log.d("CctvDebug", "ERROR LOADING VIDEO");
    }
    return view;
}

在這個問題上,當涉及到較新且不再更新的URL時,本機視頻視圖非常有限。 嘗試改用Vitamio視頻播放器。 這對於各種流功能非常有用。

<io.vov.vitamio.widget.VideoView
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"
   android:id="@+id/VideoView"/>        

另外,請勿立即調用start()方法。 僅在OnPreparedListener()回調上調用它。

Vitamio.isInitialized(getApplicationContext());

mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();

mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mediaPlayer) {
        // optional need Vitamio 4.0
        mediaPlayer.setPlaybackSpeed(1.0f);
    }
});

或者,您也可以使用KickFlip 設置非常容易,

Kickflip.initWithApiKey(API_KEY, API_SECRET);
Kickflip.startBroadcastActivity(this, mBroadcastListener);

編輯:

因此,從昨天開始,我就嘗試在視頻流上工作。 我無法在vitamio上解決它(不幸的是)。 盡管嘗試使用您提供的網址,並通過vlc應用將其流式傳輸。 盡管我還沒有嘗試過,但是您也許可以使用LibVLC 我最終使用了webview並進行了一些設置,以使其看起來不像使用webview。

webView = findViewById(R.id.wvWebview);

webView.loadUrl("http://121.58.202.110:8080/jpeg?cam=4");
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);

樣本流

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM