我需要让我的应用程序播放网络上的视频文件。我知道文件的网址是:
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:
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.
如何解决:
对于 java 库,前面的答案提供了足够好的示例。
关于android - 如何在 Android 上解析 Bonjour 域名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8470586/