热门标签 | 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.

我希望它有所帮助。


推荐阅读
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 都说Python处理速度慢,为何月活7亿的 Instagram依然在使用Python?
    点击“Python编程与实战”,选择“置顶公众号”第一时间获取Python技术干货!来自|简书作者|我爱学python链接|https:www.jian ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 使用在线工具jsonschema2pojo根据json生成java对象
    本文介绍了使用在线工具jsonschema2pojo根据json生成java对象的方法。通过该工具,用户只需将json字符串复制到输入框中,即可自动将其转换成java对象。该工具还能解析列表式的json数据,并将嵌套在内层的对象也解析出来。本文以请求github的api为例,展示了使用该工具的步骤和效果。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文是一篇翻译文章,介绍了async/await的用法和特点。async关键字被放置在函数前面,意味着该函数总是返回一个promise。文章还提到了可以显式返回一个promise的方法。该特性使得async/await更易于理解和使用。本文还提到了一些可能的错误,并希望读者能够指正。 ... [详细]
  • x86 linux的进程调度,x86体系结构下Linux2.6.26的进程调度和切换
    进程调度相关数据结构task_structtask_struct是进程在内核中对应的数据结构,它标识了进程的状态等各项信息。其中有一项thread_struct结构的 ... [详细]
  • Hello.js 是一个用于连接OAuth2服务的JavascriptRESTFULAPI库,如Go ... [详细]
  • 3年半巨亏242亿!商汤高估了深度学习,下错了棋?
    转自:新智元三年半研发开支近70亿,累计亏损242亿。AI这门生意好像越来越不好做了。近日,商汤科技已向港交所递交IPO申请。招股书显示& ... [详细]
  • React 小白初入门
    推荐学习:React官方文档:https:react.docschina.orgReact菜鸟教程:https:www.runoob.c ... [详细]
  • 篇首语:本文由编程笔记#小编为大家整理,主要介绍了Flutter添加APP启动StoryView相关的知识,希望对你有一定的参考价值。 ... [详细]
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社区 版权所有