1

I have 2 similar apps. One servers as the server and the other one can be seen as a client. Now I would to use the camera of the server app and stream this video within the app to the client via WiFi. I would like to know if there is a more or less convenient way of doing this in Android with Java. I found some posts on Stackoverflow regarding this issue like Live-stream video from one android phone to another over WiFi, Stream live video from phone to phone using socket fd or Live video streaming application on Android. But they are all about 10 years old and I would like to know if there is now a more convenient way of doing this?

Reminder: Does nobody have any good solution for this?

VanessaF
  • 515
  • 11
  • 36
  • I don't have time to write an example project but the concept is simple, especially if the "server" and "client" are on the same wifi network. Have the server create a video stream and send it through a UDP socket. Have the client create a UDP socket and listen to the server. Things only get complicated when you need more than ~10-15fps. –  Jun 29 '22 at 22:47
  • @Thanks free_coupons_for_sale_1023. Actually 15 fps would be enough but 10 fps is too less. You mentioned "Have the server create a video stream and send it through a UDP socket" --> Which Android Java class would you recommend me to use for creating a video stream and which Android Java class for the UDP socket? – VanessaF Jun 30 '22 at 18:58
  • The ~10-15 fps is an estimate; the actual rate will depend on the hardware used. In terms of the classes, `java.net.Socket` and the [Android Camera API](https://developer.android.com/guide/topics/media/camera). I'm sure there exist libraries that simplify the process, but I don't know of any at hand. –  Jun 30 '22 at 19:07
  • @free_coupons_for_sale_1023: Thanks Free Coupons for your answer. Actually one of the purposes of this question is to get to know libraries for this task. I searched in the Internet but I could only find really complex solutions as the ones I posted in my question. So I am not really sure whether there are really good libraries for that as you assume. – VanessaF Jul 01 '22 at 15:34
  • @free_coupons_for_sale_1023: Any comments on my last comment? I'll highly appreciate every further comment from you. – VanessaF Jul 09 '22 at 07:41
  • @free_coupons_for_sale_1023: Any free coupons from you for my question? – VanessaF Jul 19 '22 at 17:38
  • No. Everything that I know of is in the above comments. –  Jul 19 '22 at 17:41
  • Thanks for your comments free_coupons_for_sale_1023. Your wrote "I'm sure there exist libraries that simplify the process, but I don't know of any at hand." --> As written in my comments, I searched for quite long in the Internet to find some libraries and I could not find any. So I am questioning your assumption. Still I appreciate your input. – VanessaF Jul 19 '22 at 17:45
  • Seeking recommendations for books, tools, software libraries, and more is considered to be off-topic for this site. That being said, you may want to look into WebRTC. – CommonsWare Jul 22 '22 at 16:38
  • @CommonsWare: Thanks for your comment "CommonsWare". Actually my question is whether it is possible to send a live stream from one app to another in Android via WiFi. Others also had this question as you can see in the links above. Unforunately, they are very old (more than 10 years) and the answers point to solutions that are extremely complex. Thus, I just want to know if - after 10 years - there are easiert solutions for this purpose. So I think that the question is quite relevant (because the linked questions received many upvotes) and after 10 years it's appripiate to ask for an update – VanessaF Jul 23 '22 at 07:32
  • @CommonsWare: I had a look at WebRTC but this seems extremely complex to use as you need also many other libraries and tools for it and you need to implement steps that tend to be quite difficult and error prone (according to many comments from tutorials). Further, I don't want to create a video chat function but just to send one livestream from one Android app to another (so only one side sends a video). Do you have any idea, how I can do that in an easy way? "free_coupons_for_sale1023" suggested a UDP socket approach. Do you know any libraries that simplify this approach? – VanessaF Jul 23 '22 at 08:04
  • "So I think that the question is quite relevant" -- the subject matter is relevant for the site. Asking for libraries and other off-site resources is what makes it off-topic. See [the site documentation](https://stackoverflow.com/help/on-topic), "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.". – CommonsWare Jul 23 '22 at 10:45
  • What's wrong with a 10-year-old approach, if it solves your problem. The libraries you are looking for will be doing just that. You can write one for the community. You can also search of Android based IP Cam server and Client which are doing similar task. https://github.com/niqdev/ipcam-view – Rahul Shukla Jul 27 '22 at 04:05
  • @RahulShukla: Thanks for your comments. Well the old approaches are not only quite old but also extremely complex and I am just wondering whether after 10 year a more convenient way exists to stream a video from one app to another using WiFi – VanessaF Jul 27 '22 at 17:22
  • @RahulShukla: I seached in the Internet for many hours but I could not find any suitable library unfortunately. This is the reason for my question. Maybe if you know a good library you can tell me (the one you posted is not suitable because it only works for IP cams). I think the approach suggested by user19309143 sound not bad "Have the server create a video stream and send it through a UDP socket. Have the client create a UDP socket and listen to the server." But it would be good if there are some libraries that simplify this complex process. Do you have any advice? – VanessaF Jul 27 '22 at 17:40
  • @RahulShukla: Any further comments? – VanessaF Jul 30 '22 at 14:44
  • @RahulShukla: Any further comments? I'll appreciate it. – VanessaF Sep 10 '22 at 09:01

1 Answers1

-1

Seeking recommendations for books, tools, software libraries, and more is considered to be off-topic for this site.

As @CommonsWare said, it is off-topic. But learning how to do it from a good example will be fine. So......

https://github.com/hypeapps/Endoscope (626 stars) License: GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007

These are brief points you want to know in this open-source app. But since it is GNU licensed, if you want to fully use this, you need to make your source code GNU open-source also.

Host

VideoStream.java

/**
 * Starts the stream.
 * This will also open the camera and display the preview 
 * if {@link #startPreview()} has not already been called.
 */
public synchronized void start() throws IllegalStateException, IOException {
    if (!mPreviewStarted) mCameraOpenedManually = false;
    super.start();
    Log.d(TAG,"Stream configuration: FPS: "+mQuality.framerate+" Width: "+mQuality.resX+" Height: "+mQuality.resY);
}

RtspServer.java

/* Method PLAY */           
else if (request.method.equalsIgnoreCase("PLAY")) {
...         
requestAttributes += "url=rtsp://" + mClient.getLocalAddress().getHostAddress() + ":" + mClient.getLocalPort() + "/trackID=" + 0 + ";seq=0,";
...
// If no exception has been thrown, we reply with OK
response.status = Response.STATUS_OK;
}

Client Play: It uses a media player.

@Override
public void configureMediaPlayer(Uri videoUri) {
    ...
    ...
    try {
        mediaPlayer.setDataSource(this, videoUri);
        mediaPlayer.prepareAsync();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Stanley Ko
  • 3,383
  • 3
  • 34
  • 60
  • Thanks for your post Stanley. Actually I don't want an app that does that but just the code for it. Furthermore, I can't make my project open source. This is why your suggested solution does not really help me. Still I appreciate your post. – VanessaF Jul 28 '22 at 16:03
  • I think the approach suggested by user19309143 sound not bad "Have the server create a video stream and send it through a UDP socket. Have the client create a UDP socket and listen to the server." But it would be good if there are some libraries that simplify this complex process. Do you have any advice? – VanessaF Jul 28 '22 at 16:04
  • @UmerFarooq: Thanks for your comment Umer. Oh that's annoying. There does not seem to be a good solution in Android for sending a live stream from one app to another in Android via WiFi. I assumed that there should be a solution for this but each option has significant drawbacks. I wanted to try it with the UPD socket approach but now that you say this is quite challenging and error prone, I am not sure whether I should try it or not. Really strange and kind of frustrating that just sending a video seems to be so extremely difficult in Android, even after so many years. – VanessaF Jul 28 '22 at 18:52
  • @UmerFarooq: Any further comments? – VanessaF Jul 30 '22 at 14:44
  • @VanessaF few years ago I did a project for my friend which streamed video over Wi-Fi (Wi-Fi Direct) using [libstreaming](https://github.com/fyhertz/libstreaming). At first libstreaming seams difficult but once you get into its simple. First search for video streaming protocols and then look for their libraries or try your own UDP socket approach. I Don't know if streaming a video over websocket is good idea but you should alteast try it. I used websockets in [SensorServer](https://github.com/umer0586/SensorServer) for Streaming Sensor. – Umer Farooq Jul 30 '22 at 17:23
  • @UmerFarooq: Thanks for your answer Umer. Unfortunately it seems that there is no good solution for streaming a video from one phone to another via Wifi using Android. This is something I did not expect to be totally honest as video streaming has becoming quite important. Most probably I will not include such a feature in my app as all the options are extremely complex and challgenging to implement. – VanessaF Jul 31 '22 at 07:34
  • @UmerFarooq: Thanks for your comments. Any further ideas? – VanessaF Aug 29 '22 at 16:40
  • @UmerFarooq: Do you have any further ideas how to stream a video from one app to another in Android over WiFi? – VanessaF Sep 10 '22 at 09:03
  • @VanessaF No, I don't have any further ideas – Umer Farooq Sep 11 '22 at 02:21
  • @UmerFarooq: Thanks Umer for your comment. Could you imagine where else I can get more help on this topic. Apparently the stackoverflow community does not have much experience regarding video streaming in Android. What would you advice me to do? – VanessaF Sep 11 '22 at 07:48