Android - MediaPlayer 通过使用 IP 而不是地址开始播放得更快。为什么?

发布于 2024-12-17 05:21:02 字数 446 浏览 3 评论 0原文

我正在使用 mediaPlayer.setDataSource 方法来设置 rtsp 流。它具有以下格式:

 rtsp://X/vod/" + stringEncoded +"/mp4:" +  music + ".mp4

事实证明,当我将直接 IP 放入 X 时,音乐将在大约 4 秒后开始播放。然而,当我输入地址时,需要15秒才能开始播放!

这不是 DNS 的问题,因为它可以立即解决地址问题,而且我还有一个使用相同地址的 iOS 应用程序,它可以立即运行。这可能是 Android 解释 DNS 返回的 IP 的方式存在问题。

我无法使用直接 IP,因为我必须平衡 DNS 中的请求(将每个请求发送到不同的计算机(不同的 IP))。

有人知道为什么当我使用地址而不是 IP 时 Android 需要更长的时间才能开始播放歌曲吗?

先感谢您!

I am using the mediaPlayer.setDataSource method to set a rtsp streaming. It has the following format:

 rtsp://X/vod/" + stringEncoded +"/mp4:" +  music + ".mp4

Turns out that when I put the direct IP in X, the music starts playing in about 4 seconds. However, when I put the address, it takes 15 seconds to start playing!

This is not a problem of DNS because it solves the address instantly and I also have an iOS application that uses the same address and it works instantly. This is probably some problem in how Android interprets the IP returned by the DNS.

I can't use the direct IP because I must balance the requests in the DNS (sending each request to a different machine (a different IP)).

Does anybody have any clue why android takes so much longer to start playing a song when I use the address instead of the IP?

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东北女汉子 2024-12-24 05:21:02

我最终使用 java InetAddress 类获取 IP 并在 URL 中使用该 IP。这样就成功了。这是代码:

 // Get domain name from URL
 String domainName = new String("my_address_here");

 // Get IP address as string
 InetAddress inet = null;

 try {
       inet = InetAddress.getByName(domainName);
 } catch (UnknownHostException e) {
       Log.i("[DNS Problem]", "The IP address cannot be resolved for " + domainName);
 }
  String    resolvedIP = inet.getHostAddress(); 

我仍然不知道为什么 setDataSource 方法会与地址混淆。

I ended up getting the IP using the java InetAddress class and using that IP in the URL. That way it worked. Here is the code:

 // Get domain name from URL
 String domainName = new String("my_address_here");

 // Get IP address as string
 InetAddress inet = null;

 try {
       inet = InetAddress.getByName(domainName);
 } catch (UnknownHostException e) {
       Log.i("[DNS Problem]", "The IP address cannot be resolved for " + domainName);
 }
  String    resolvedIP = inet.getHostAddress(); 

I still have no idea why the setDataSource method messes up with the address though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文