热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

评估连接速度的最佳方法-Bestwaytoevaluateconnectionspeed

Imdevelopinganappwhichneedstogetmusicfilebystreamingforplayinglive.我正在开发一个应用程序,需要通过流

I'm developing an app which needs to get music file by streaming for playing live.

我正在开发一个应用程序,需要通过流媒体播放音乐文件进行现场直播。

In the request song api I can specify the bandwith (eg: 50kbps, 100kbps, 300, 600 or 1 Mbps).

在请求歌曲api中,我可以指定带宽(例如:50kbps,100kbps,300,600或1Mbps)。

The more the bandwith is big, the more the file will get time to be fetched. As I don't want the users to be restricted about that I have multiple choices to deal with it:

bandwith越大,文件就越有时间获取。由于我不希望用户受到限制,因此我有多种选择来处理它:

  • Detect wether the phone is using 3g, wifi or Edge and specify an bandwith for each connection speed.

    检测到手机正在使用3g,wifi或Edge,并为每个连接速度指定带宽。

  • Let the user decide the quality of the song he will get: like youtube (but the users won't be people that know much about computing: the more easy is the software, the more it will fit)

    让用户决定他将获得的歌曲的质量:像youtube(但用户不会是那些了解计算的人:软件越容易,它就越适合)

  • Having a way to evaluate properly the connection speed: Like fetching a file, measure the time that it took and set the bandwith.

    有办法正确评估连接速度:就像获取文件一样,测量它所花费的时间并设置带宽。

I know that connection speed could vary a lot if user loose the wifi, or is using 3g moving in the street. And the thing is that I can't change the bandwidth when the song will be playing.

我知道如果用户放松wifi,或者在街上使用3g移动,连接速度可能会有很大差异。而事实是,当歌曲播放时我无法改变带宽。

Maybe you have experience about that you would like to share?

也许你有关于你想分享的经验?

Thank you!

谢谢!

4 个解决方案

#1


38  

Facebook released a library for this:

Facebook为此发布了一个库:

https://github.com/facebook/network-connection-class

https://github.com/facebook/network-connection-class

this wasn't existing in 2011..

这在2011年不存在..

#2


4  

why not try to change your view of things. Try to flow with your users. say your user wishes to download 128 kbit quality song. you start the download , WHILE downloading you make an average download time, take a few seconds for this average to stabilize, and if it's below certain value make a pop up to tell the user that his connection is too slow for the current bandwidth and ask him if to lessen the quality or to keep downloading slowly.

为什么不试着改变你对事物的看法。尝试与您的用户一起流动。说你的用户希望下载128 kbit的优质歌曲。你开始下载,下载你平均下载时间,花几秒钟让这个平均值稳定下来,如果它低于一定值,弹出告诉用户他的连接速度太慢,不能满足当前的带宽要求他是否要降低质量或继续慢慢下载。

This will:

这会:

  1. let the users the option to always assume they can get the best quality media.
  2. 让用户可以选择始终假设他们可以获得最优质的媒体。
  3. let u do your check in runtime and change the quality accordingly while downloading without the need to pre check.
  4. 让你在运行时检查,并在下载时相应地改变质量而无需预先检查。
  5. keeps your app simple to users.
  6. 让您的应用程序对用户简单。

I know i'm not answering your specific requirement, i'm just offering a different view.

我知道我没有回答你的具体要求,我只是提供了一个不同的观点。

#3


4  

protected String doInBackground(String... urls) {
    String respOnse= "";

    startTime = System.currentTimeMillis();
    for (String url : urls) {
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        try {

            HttpResponse execute = client.execute(httpGet);
            InputStream cOntent= execute.getEntity().getContent();


            BufferedReader buffer = new BufferedReader(
                    new InputStreamReader(content));
            String s = "";
            while ((s = buffer.readLine()) != null) {
                response += s;
            }
            endTime = System.currentTimeMillis();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return response;
}

@Override
protected void onPostExecute(String result) {
    // TODO Auto-generated method stub


    long dataSize = result.length() / 1024;
    takenTime = endTime - startTime;
    long s = takenTime / 1000;
    double speed = dataSize / s;

    Toast.makeText(context, "" + s + "kbps", Toast.LENGTH_SHORT).show();
}

#4


2  

Detect network connection type on Android

检测Android上的网络连接类型

You can check all available options here: http://developer.android.com/reference/android/telephony/TelephonyManager.html

您可以在此处查看所有可用选项:http://developer.android.com/reference/android/telephony/TelephonyManager.html

This can fix the mobile network type but can't help you with the Wifi speed, you should code it by downloading something from a server you know and calculate the time.

这可以修复移动网络类型,但无法帮助您获得Wifi速度,您应该通过从您知道的服务器下载内容并计算时间来对其进行编码。

I hope it helps.

我希望它有所帮助。


推荐阅读
author-avatar
justnicetwo
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有