English 中文(简体)
Android的视频流
原标题:Video Streaming in Android

我正在开发一个程序, 试图显示在网络服务器上流出的视频。 我有视频流的 HTTP 链接。 要连接到网络服务器, 我正连接到一个特定的 WIFI, 这使我能够访问视频 。

我已经解决了 WIFI 的连接问题。 当我试图用 VideoView 在应用程序上显示视频时, 我遇到了一个问题。 我使用了一个工具, 显示我正在接收服务器的数据。 所以我的应用程序正在接收视频的数据包, 但无法显示它 。

代码是这样的:

    private VideoView videoView;
    videoView = (VideoView)findViewById(R.id.VideoView_videoOnly);
    ....
    ....
    //connect to the router
    String ip = "http://192.168.2.250";
    URL url = null;
    try {
        url = new URL(ip);
    时 时 catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    时 时

    URLConnection connection = null;
    try {
        connection = url.openConnection();
    时 时 catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    时 时

    String vidLink = "http://XXXX:[email protected]/axis-cgi/mjpg/video.cgi";
    //set up video streaming
    MediaController mc = new MediaController(this);
    mc.setAnchorView(videoView);
    mc.setMediaPlayer(videoView);
    Uri video = Uri.parse(vidLink);
    videoView.setMediaController(mc);
    videoView.setVideoURI(video);
    videoView.start();

时 时

时 时

XXXX:XXXX 是访问视频流的用户名和密码

问题回答

According to the URL you are using, one can guess, you are receiving the stream in the MJPEG format. MJPEG is not natively supported by Android. You will have to break your stream into jpegs, then create a Bitmap from each jpeg, then display bitmaps one by one.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签