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

我希望它有所帮助。


推荐阅读
  • 2023年京东Android面试真题解析与经验分享
    本文由一位拥有6年Android开发经验的工程师撰写,详细解析了京东面试中常见的技术问题。涵盖引用传递、Handler机制、ListView优化、多线程控制及ANR处理等核心知识点。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 如何配置Unturned服务器及其消息设置
    本文详细介绍了Unturned服务器的配置方法和消息设置技巧,帮助用户了解并优化服务器管理。同时,提供了关于云服务资源操作记录、远程登录设置以及文件传输的相关补充信息。 ... [详细]
  • 360SRC安全应急响应:从漏洞提交到修复的全过程
    本文详细介绍了360SRC平台处理一起关键安全事件的过程,涵盖从漏洞提交、验证、排查到最终修复的各个环节。通过这一案例,展示了360在安全应急响应方面的专业能力和严谨态度。 ... [详细]
  • 本文探讨了如何优化和正确配置Kafka Streams应用程序以确保准确的状态存储查询。通过调整配置参数和代码逻辑,可以有效解决数据不一致的问题。 ... [详细]
  • 本文详细介绍了macOS系统的核心组件,包括如何管理其安全特性——系统完整性保护(SIP),并探讨了不同版本的更新亮点。对于使用macOS系统的用户来说,了解这些信息有助于更好地管理和优化系统性能。 ... [详细]
  • 在使用 MUI 框架进行应用开发时,开发者常常会遇到 mui.init() 和 mui.plusReady() 这两个方法。本文将详细解释它们的区别及其在不同开发环境下的应用。 ... [详细]
  • 使用Python在SAE上开发新浪微博应用的初步探索
    最近重新审视了新浪云平台(SAE)提供的服务,发现其已支持Python开发。本文将详细介绍如何利用Django框架构建一个简单的新浪微博应用,并分享开发过程中的关键步骤。 ... [详细]
  • 本文将详细介绍如何在没有显示器的情况下,使用Raspberry Pi Imager为树莓派4B安装操作系统,并进行基本配置,包括设置SSH、WiFi连接以及更新软件源。 ... [详细]
  • 云屏系统基于嵌入式微系统msOS,旨在解决当前嵌入式彩屏GUI编程中硬件要求高、软件开发复杂、界面效果不佳等问题。该系统通过结合MCU和Android技术,利用Html5+JavaScript实现高效、易用的图形用户界面开发,使嵌入式开发人员能够专注于业务逻辑。 ... [详细]
  • 本文介绍如何在 Android 中通过代码模拟用户的点击和滑动操作,包括参数说明、事件生成及处理逻辑。详细解析了视图(View)对象、坐标偏移量以及不同类型的滑动方式。 ... [详细]
  • 本文介绍了如何通过设置中继器或桥接第二台路由器来增强家庭网络覆盖,提高网络稳定性和速度。 ... [详细]
  • 本文详细介绍如何在智能手机上更改DNS设置,通过简单的步骤让您的网络浏览体验更加流畅。 ... [详细]
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社区 版权所有