How to resolve Bonjour domain name on Android?

I need my application to play a video file located on my network. I know the file url is:

http://something.local/abc.mp4

Now that I manually replace "something.local" with my true ip address, MediaPlayerit has no playback problems. However, when I have the above address, there are MediaPlayerno errors since error (1, -1007).

Therefore, I assume that this is because Android does not understand "something.local" as correct.

My question is: how can I "translate" something .local to ip itself, then to transfer it to MediaPlayer?

A little caveat: I believe that it MediaPlayerdoes not work with IPv6 addresses, so please keep that in mind ...


Just a side note if this makes my situation clearer: when I run ping something.local -4on a Windows command prompt, it returns:

Pinging something.local [192.168.1.126] with 32 bytes of data:
Reply from 192.168.1.126: bytes=32 time=145ms TTL=64
Reply from 192.168.1.126: bytes=32 time=112ms TTL=64
Reply from 192.168.1.126: bytes=32 time=32ms TTL=64
Reply from 192.168.1.126: bytes=32 time=169ms TTL=64

This translation, in which windows were transitioning from something.local -> 192.168.1.126, is what I want to do in my Android application.

+5
source share
3 answers
+4

jmDNS api.. .

JmDNS jmdns =  JmDNS.create();

DNSEntry addressEntry = jmdns.getCache().getDNSEntry(name, DNSRecordType.TYPE_A, DNSRecordClass.CLASS_ANY);
 if (addressEntry instanceof DNSRecord) {
      ServiceInfo cachedAddressInfo = ((DNSRecord) addressEntry).getServiceInfo(true);
      if (cachedAddressInfo != null) {
      for (Inet4Address address : cachedAddressInfo.getInet4Addresses()) {
          //  use the `address`
      }
 }
+3

java, net APIS Android .

http://docs.oracle.com/javase/1.4.2/docs/api/java/net/InetAddress.html

However, success will depend on the correct network configuration. Your device receives the DNS server configuration through DHCP - so you are at the mercy of the network provider.

-2
source

All Articles