Android stream audio to other devices - android

Hello I'm in the early stages of an app and part of it i need to stream audio from one device to multiple devices. I have been googling around looking for the best solution on doing this so far i found these two projects each with problems.
Spydroid http://code.google.com/p/spydroid-ipcamera/
Problem The problem with this one is it creates an rtsp stream which is limited to one connected device. If i browse to the link on both of my computers i see both clients connect in the app but then the second one to connect instantly disconnects and the app says my phone doesn't support this feature. I dove into the source and found in the Session.java file there were if statements with comments above them saying prevents two connections from being made i commented out the if statements and the catch clause caught me after running it. This project would be perfect if i could get it to work with multiple connections as it works over 3g.
PttDroid http://code.google.com/p/pttdroid/
Problem The problem with this one is it allows me the multiple connections i need but i only can get it working over wifi. It says on the home page there that it works over 3g but only the unicast i need multi cast over 3g and wifi and i was unable to get the unicast to work as well over 3g.
So my question comes down to this what path should i go down and look more into for streaming audio from my android device to multiple computers and other android devices.
Thank you very much for any help!

Cellular networks do not usually support multicast packets. The cellular routers simply don't route them, so that is a dead end.
You thus need to do unicast to multiple destinations which may be challenging for the limited cellular bandwidth of the phone. You are very likely to run into contention on the cellular bandwidth with just one or two streams, even if you can get them running out of the same device. (Multiple Spydroid streams of the same file for instance.)
If I were building a system to do this, I would consider setting up a server to do reflection. So I would look to use something like Spydroid to run an RTSP stream up to a server and then reflect that off the server to a number of subscribers. This is not a small project but would allow you to stream to multiple users using the servers higher bandwidth.
There is apparently a project going after this reflector strategy here:
https://code.google.com/p/js4ms/wiki/RTSPMulticastReflector
I have not tested it at all to know if it works, but that should at least get you started on the right path.

Related

Transfer large files between Android and Node.js

I have a photo-taking Android app (written in React Native, but I can add native modules if need be) that pairs with a gallery-type app on the user's computer (written in Electron with React). The number of photos can be large (we've had upwards of a thousand photos at a time), and they need to be transferred, uncompressed and uncropped, to the computer app. I need a reliable way to do this without routing the data through the Internet first.
Things I've tried
Node USB: Looks like a good library, but is unusable without installing a driver on the user's computer. The driver then appears to replace the default Windows USB driver, and the phone becomes inaccessible through normal means (opening a file explorer in Windows). Perhaps there's some way to switch drivers "on the fly", using the driver only while transferring photos, and then switching it back out for the system driver once we're done?
ADB: This is the original solution I tried, and it does exactly what I need it to, with two dealbreaking problems: for one, the phone needs to have Dev Mode enabled, and for two, ADB doesn't seem to recognize all devices (we've had a lot of trouble getting it to work with an LG V20, for example). The ideal answer to this question would be something like ADB without those two issues.
WiFi routing: we connect the phone to the same WiFi network as the host computer, use WebSockets to handshake IPs through the Internet, and then initiate a direct connection over the WiFi network. If I cannot find any other solutions, this will likely be the one I'll go for. The biggest problem with this option is the relatively large amount of manual setup required. Our users don't tend to be very technically savvy, and I don't know how reasonable it is to assume they will have WiFi in their home. At any rate, this cannot be the only option for transfer. Further, transferring gigabyte(s) of photos over the wireless network will cause a slowdown for everyone on the same network.
Tether routing: we tether the phone to the computer, and initiate a direct connection much in the same way as in the above step. The downsides to this method are that only phones with SIM cards can activate tethering (not all of our phones have SIM cards, as connectivity isn't their primary purpose for our needs), plus all of the other traffic on the computer will now be routed through the phone, which would be bad for customers' data caps who do have SIM cards. Additionally, there is no way to programmatically turn tethering on, there is only the ability to bring up the tethering menu; it's not too big a dealbreaker, but the other two very much are.
Bluetooth: Generally meets my requirements, but the data transfer rate is far too low, being an order of magnitude below WiFi.
WiFi Direct: I did not actually try this, because I could not find a working way to have the PC accept the WiFi Direct connection. It promises exceptional speeds, but there are no modules or libraries that I've found that would help me enable it.
SD Card: The lowest of the low tech methods, just save everything to the SD card and have the client take the card out and plug it into their computer. Would hands-down go with this, except for the need for a SD card port (guaranteed neither for the client's computer or their phone).
The obvious: manual drag and dropping required files from the phone to the PC. This is how we do things now, and it's fraught with problems. Text files have the last 15-20 characters cut off from them, for some reason, during transfer; many of the photos on the device do not initially show up due to the known issue with MTP not forcing a media rescan on the phone; and users sometimes drop files in the wrong places, leading to unnecessary support calls. This method surely needs to be replaced.
I've been searching for a solution for this problem for two months now, and it's hard to believe that nobody has had a use case for Android like this. It's been made clear that USB communication between Android and PC is non-trivial, I'm sure there are programs that do that, Windows to start off with. Yet try as I might, there are no solutions that work out of the box. Has anyone dealt with an issue like this before? What were your solutions? How would you approach this problem?
When downloading large files on Android it is recommended to use Download Manager, it supports a lot of native features like the progress bar, and notification, also the download task will be handled by OS, and more efficient.
React Native Fetch Blob library support this feature
You dont really need to route the data through the internet.
You can just exchange meta data through the internet:
Extend your desktop app with folder-import functionality (Plug your phone normally via USB, brose to the folder, import).
When you execute this process, let it notify a webservice of some sort (push notifications? Im no phone-app dev.) with which files the desktop-app has imported from which device (ids, filenames, ...) and the phone gets this meta data and can continue its process of whatever it is doing!
Obviously the best solution is a communication channel over USB. Until you figure that one out, you could implement it temporarily this way!

Streaming data from an Android device to a PC via USB

I need to stream a set of numbers, 6 floats, from an android device to a PC, to which it is connected by a USB cable. All the solutions I have found proposes using a WiFi connection. However, I have found that the latency caused by this is not acceptable. As such I have decided that I am going to hire someone to integrate the components, thus enabling direct communication. Until then, however, I want to try a variety of devices to see what works and the quickest way to "Integrate" two devices is by allowing them to share a (US)Buss. However, this is the one field I have zero experience with.
Do you make a socket and treat the connection as a network connection or is there another fancier way to achieve what I want? I have seen some talk about making a device driver for this purpose and I do not feel like crashing my OS 500 times again. I find it hard to believe that the android devices do not have some kind of driver already made that I can exploit.
The android code is written in Java, but it could be changed depending on what people suggest. The main chunk of mys system lies on the PC and is written in C++.
I need the latency of the stream to be as low as possible since the entire system needs to be as real time as possible. The limit is 15 ms between data acquisition on the device and the rendering of the simulation on the PC.
TL/DR: I need to stream data from a program on an android device to a PC with as little latency as possible; i.e. one way communication. As long as I can stream bytes I can design protocols and translate the bytes on the receiving end. My global cap is 15 ms and I need to stream continually updated 6 floats. What is the best way to achieve this?
Thank you in advance for your help.
Raw USB is probably not the way to go. USB is a device-oriented specification and cannot be used in a general send-arbitrary-bytes-across-a-wire way.
If Wi-Fi really is too slow, you could try purchasing an Android-compatible USB-Ethernet adaptor and connecting the device to the computer via a wired network connection, which might reduce the latency. Android recognises many types of these adaptors and you communicate over the network connection in the same way as other networks.
We ended up using the ADB brigde and it seems to be stable and fast enough for our purposes. All we had to do was to open a socket and connect with TCP. For some reason it fails when we try to connect with UDP, but I assume this might be due to ignorence on our part.

How to sniff Bluetooth traffic in Android?

I would like to know if there are any apps/api tools to track all the bluetooth connections happening in android? I tried using hcidump via BusyBox, but the trace is truncated, it does not display all the data I need.
I am trying to receive data from blood pressure monitor in android using Bluetooth HDP profile. However, the connection works at the beginning, and then stops. Therefore, I would like to use some packet sniffer to see the low level bluetooth connection for better debugging.
I found out that traces from hcidump tools are not truncated, and I think this is a perfect solution. However, I have to copy the trace from android to the pc evry time (e.g. sending by e-mail) and therefore it is a cumbersome work. Would be great if there was a tool to get access to the terminal emulator of android. Btw, BusyBox provides also some other very useful tools from Linux.
There are two options for this currently, the first is to use a software-defined radio that supports the ISM band (at least 2.4 to 2.485 GHz). This will allow you to grab any radio signals within the bluetooth range and will be especially useful if you're trying to identify interfering signals.
The downside is that you'll be receiving totally raw waveforms which you then need to demodulate using something like the gr-bluetooth stack.
The other option is a specialized device like the Ubertooth.

Make a mobile device a remote control for a tablet?

I'm trying to make an app on an Android device that will control an application on an iPad or Android tablet. (I'm testing with an Samsung Galaxy S2 and an iPad 2).
The application is pretty simple for now. When one selects a colour on the Android mobile, that colour displays on the tablet device.
The question is, how to connect the two devices. Just now I've verified that I can pair the two devices using Bluetooth. Also, the Samsung has a "Kies" Wifi Direct feature (which I don't understand fully), that allows the iPad to connect to the Galaxy as a wifi hotspot.
The connections are there, but I don't know if either protocol can be used to actually get the apps to talk to each other to get the control I'm looking for.
Should I be using Bluetooth, Wifi, or something else?
And in whichever case, how?
My opinion is that you should not stick so much around the physical medium used for connectivity either is WiFi or Bluetooth. You should abstract this aspect, in both cases you will be using sockets (I'm speaking about Android), if it's Bluetooth you will be using Bluetooth Sockets, if it's WiFi: TCP sockets. You could have a intermediate layer that abstracts the type of connection and through a factory to use either Bluetooth or TCP.
Bluetooth - http://developer.android.com/guide/topics/wireless/bluetooth.html
For WiFi you should study if P2P would help.
You will need two applications:
- one on the tablet - the server which listens for commands from the client (change color, do this or this)
- second on the smartphone - the client which sends commands.
I've built a few apps that do exactly that between iPhone and iPad. But the principle is the same. I used Bonjour networking. It's just a fancy name for ZeroConfig networking between devices. It's written originally by Apple but it's open source so there should be Android support out there for it too. Really simple and easy to work with.
If you already have a working connection then you already have the first half of your answer, that said you should really consider implementing a solution that uses a variety of connection types, WIFI, Bluetooth, etc.. The question I think you are really asking is how to pass data and messages between the apps once you have the connection.
There are a lot of ways to accomplish this. You could implement your own lightweight message passing system. If you haven't done this before it is more complicated than it originally seems, especially as you would be required to implement the system for each OS you end up using.
Should I be using Bluetooth, Wifi, or something else?
It depends on what situations you want your program to work in.
Bluetooth can provide a direct connection between your devices. A potential issue with bluetooth is that it has a limited range. If you're devices need to be far away from each other, you may want to go with wifi. Otherwise, bluetooth could work great.
If both devices are connected to the internet, you can make them talk to each other through there. The advantage of this approach is that it doesn't matter how far apart your devices are as long as they're both online. A disadvantage is that you'll have to figure out how to find the tablet's ip address before you can talk to it. This is actually a HUGE disadvantage because it can be quite problematic if both of your devices are not on the same wifi. You could have the user type in the destination ip address, but you'll have problems getting it to work if the user is behind a router (which will almost always be the case). The point is, it gets hairy.
If both of your devices are on the same wifi, you can use ZeroConf AKA bonjour (like Dancreek said) to figure out what ip address you need to send info to. I've previously used a library called jmdns (easy to find with google) to implement zero configuration networking. It's good because the user doesn't have to worry about ip addresses... it's intuitive for the user.
And in whichever case, how?
Networking is a pretty big topic, so I can't expand on this question to much. Short answer is, it depends on what method you choose. Search for some tutorials and start by getting one of your devices to send something as simple as an int to the other.

How to utilize network for p2p file sharing on Android Platform?

I'm working on some apps for the android platform and I have two problems that I'm not quite sure how to approach, and both are closely related.
How can I send a relatively small data file from one android device to another (preferably over the internet or directly through wireless network)?
Is it possible to create a temporary p2p live data stream from one android device to another? An example application would be to stream low-res video from phone A's camera to phone B, or audio.
I would much appreciate being pointed in the right direction on either issue (File transfer or real time data transfer).
You could try to get Google's library libjingle to work on Android. It provides quite advanced NAT Traversal capabilities, which should be able to get through the carriers' firewalls.
One approach would be to use the socket classes in java.net.
To use WiFi to send data among devices, you can try to establish an ad-hoc network among the devices that will communicate. I think you can use Android's WiFi API to do that. Once you have the ad-hoc network setup, you can establish a simple TCP connection between the devices and transfer the files.
Sockets do not work between phones. I've tried with two actual phones using socket communications and there seems to be a firewall in the carriers that prevents communications on ports different than port 80. Then if you try to use port 80 you get a 'Permission Denied' exception.
One possibility is to investigate the JXTA framework. The Practical JXTA II book is available online for reading at Scribd.

Categories

Resources