android - 如何在 Android 上解析 Bonjour 域名?

标签 android bonjour

我需要让我的应用程序播放网络上的视频文件。我知道文件的网址是:

http://something.local/abc.mp4

现在,当我用它的真实 IP 地址手动替换“something.local”时,MediaPlayer 播放它没有问题。尽管如此,当我有上述地址时,MediaPlayer 出错并显示 error (1, -1007)

所以我假设这是因为 Android 不理解“something.local”是正确的。

我的问题是:我如何自己将 something.local“翻译”成 ip,以便我可以将它传递给 MediaPlayer

一个小警告:我认为 MediaPlayer 不适用于 IPv6 地址,所以请记住这一点...


只是一个旁注,以防它让我的情况更清楚:当我在 Windows 命令提示符下运行 ping something.local -4 时,它返回:

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

Windows 从 something.local -> 192.168.1.126 的翻译是我想在我的 Android 应用程序中做的。

最佳答案

首先,您需要阅读有关 Bonjour(iOS 术语)或零配置(Linux 术语)的文档。

了解什么是 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.

如何解决:

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

对于 java 库,前面的答案提供了足够好的示例。

关于android - 如何在 Android 上解析 Bonjour 域名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8470586/

相关文章:

android - 创建 SO 用户指定的初始屏幕时出错

ios - 有什么方法可以在无线网络上检测 iPad 或 iPhone?你好?

iphone - iOS 上的 NSNetServiceBrowser/Bonjour 问题

bonjour - 在其他机器上找不到 JmDNS 服务

objective-c - NSNetService 委托(delegate)未被调用

iphone - iOS Bonjour 设备连接限制?

android - 如何在android中裁剪图像?

android - 带分页库的无尽 RecyclerView 中的 AdMob 广告

java - 为什么我的简单计时器应用程序每次暂停时都会变得更快?

java - 如何在 Java/Android 中访问圣经文档