5

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

http://something.local/abc.mp4

Now, when I manually substitute "something.local" with its true ip address, the MediaPlayer has no problem playing it. Nonetheless, when I have the above address, the MediaPlayer errors out with error (1, -1007).

So I'm assuming this is because Android doesn't understand "something.local" as being correct.

My question is: How can I "translate" something.local into an ip myself, so that I can then pass it into MediaPlayer?

A small caveat: I believe that MediaPlayer does not work with IPv6 addresses, so please keep that in mind...


Just a side note, in case it makes my situation clearer: When I run ping something.local -4 in the 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

That translation where windows went from something.local -> 192.168.1.126 is what I want to do in my Android app.

yydl
  • 24,284
  • 16
  • 65
  • 104
  • http://home.heeere.com/tech-androidjmdns.html – Jens Dec 15 '11 at 12:49
  • @Jens I can't seem to find anything in jmdns that allows resolving a domain. Can you point out where I should be looking? – yydl Dec 18 '11 at 23:39
  • Hm, isn't Bonjour just Apple-speak for zeroconf? In that case I'd look at the [DiscoveryActivity](https://github.com/twitwi/AndroidDnssdDemo/blob/master/AndroidDnssdDiscovery/src/com/heeere/androiddnssd/discovery/DiscoveryActivity.java). If it's not - then my bad :-D – Jens Dec 19 '11 at 08:24

3 Answers3

4

Firstly, you need read document about Bonjour (iOS term) or Zero Config (Linux term).

To understand what's something.local:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NetServices/Articles/about.html#//apple_ref/doc/uid/TP40002458-SW1

For example, if a user types steve.local. into a Web browser, this tells the system to multicast the request for steve on the local network instead of sending it to the conventional DNS server. If a Bonjour-enabled computer named steve is on the local network, the user’s browser is sent the correct IP address for it. This allows users to access local hosts and services without a conventional DNS server.

For how to resolve it:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NetServices/Articles/NetServicesArchitecture.html#//apple_ref/doc/uid/20001074-SW1

For java library, previous answers provided good enough example.

pinxue
  • 1,736
  • 12
  • 17
3

You should try this snippet with jmDNS library api.. may need some changes.

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`
      }
 }
Ron
  • 24,175
  • 8
  • 56
  • 97
  • 1
    The only problem is that methods you referenced (like getCache()) are not public and not part of the API... – yydl Dec 14 '12 at 20:47
-2

You have access to java,net APIS on android and can use them to resolve adresses.

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

However, success will depend on network proper configuration. Your device receives DNS server setup via DHCP - so you are at mercy of network provider

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
  • I tested this on two different Android devices. They both were not able to resolve the bonjour name. (i.e. "something.local") – yydl Dec 18 '11 at 23:38
  • @Konstantine the entire point of bonjour/zero conf is to not have any DNS server setup at all. This needs to be done without any involvement of DNS. Presumably @yydi is talking about a typical home network, with a PC on it which will respond a zero config lookup for `something.local`. – Abhi Beckert Dec 20 '11 at 00:08
  • DNS setup is still there - you just do not see it. – Konstantin Pribluda Dec 20 '11 at 10:22
  • @KonstantinPribluda I think it depends on the underlying implementation. Your answer works on my Windows PC (w/ Bonjour installed -- although I'm not sure if that has to do with it). On my Android, on the other hand, it fails. – yydl Dec 21 '11 at 00:02