Stream live video from phone to phone using socket fd

后端 未结 4 1554
我寻月下人不归
我寻月下人不归 2020-12-04 10:43

I am new to android programming and have found myself stuck I have been researching various ways to stream live video from phone to phone and seem to have it mostly functio

相关标签:
4条回答
  • 2020-12-04 10:53

    I found an open source project for implementing what I was trying. It processes the video with metadata through an IP camera. Although it does not send video directly to a phone, it does broadcast video for various devices to watch. The source code can be found at the following project page http://code.google.com/p/ipcamera-for-android/.

    With Android 4.4 there is another way to play a live MJPEG stream. The stream you are playing should be broadcast by the other device on a port over UDP. Let's say we have a stream being broadcast on 192.168.0.101:8080. We can play the stream by adding a WebView to our layout. Then in our activity we do the following:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mjpeg_activity);
        // Grab instance of WebView
        WebView webView = (WebView)findViewById(R.id.webViewStream);
        // Set page content for webview
        webView.loadData("<html><head><meta name='viewport' content='target-densitydpi=device-dpi,initial-scale=1,minimum-scale=1,user-scalable=yes'/></head><body><center><img src=\"http://192.168.0.101:8080/\" alt=\"Stream\" align=\"middle\"></center></body></html>", "text/html", null);
        webView.getSettings().setBuiltInZoomControls(true);
    }
    

    In the content we tell the webpage to use the device's dpi. To support the user to pinch zoom on the webpage I have added the following initial-scale=1,minimum-scale=1,user-scalable=yes. Initially the image is it's original size and cannot get smaller. The user can now scale to zoom into the image and out to it's original size. Removing the minimum scale will give the user complete control over zoom, but can result in making the image so small you can't find it.

    0 讨论(0)
  • 2020-12-04 11:00

    Take a look at Streaming to the Android MediaPlayer , which may have some helpful tips on how to do the streaming. I suspect the issue is that Android's trying to seek in the file, but being a network socket - it can't. Maybe some sort of disk/memory buffer that supports seeking could help?

    0 讨论(0)
  • 2020-12-04 11:02

    You have to set the recorder output format 8(MPEG-2TS, only available from android version 3.0+). In this case record the video in this format and sent stream to other phone and save it in a file. And play it after writing some data in the file, then you can see live stream.

    Note- You can't directly play through socket file descriptor, because socket fd is not seekable. If you use socket fd you will get "offset error". Recording is possible, but play is restricted.

    0 讨论(0)
  • 2020-12-04 11:10

    Download source code from: http://code.google.com/p/ipcamera-for-android/ (https://github.com/Teaonly/android-eye)

    Build the jni first (use ndk-build with cygwin)

    I could build this project successfully

    0 讨论(0)
提交回复
热议问题