Android提高第二十篇之MediaPlayer播放网络音频

本文详细介绍了如何使用Android的MediaPlayer类实现网络音频的在线播放功能。通过创建MediaPlayer实例、设置音频流类型、监听缓冲更新和完成事件,以及结合SeekBar进行播放进度控制,实现了完整的音频播放解决方案。示例代码中提供了播放、暂停、停止等操作的实现,并给出了布局文件和关键类的源码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.youkuaiyun.com/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

本文来自http://blog.youkuaiyun.com/hellogv/ ,引用必须注明出处!

     以前曾经地介绍过MediaPlayer的基本用法,这里就深入地讲解MediaPlayer的在线播放功能。本文主要实现MediaPlayer在线播放音频的功能,由于在线视频播放比在线音频播放复杂,因此先介绍在线音频播放的实现,这样可以帮助大家逐步深入了解MediaPlayer的在线播放功能。先来看看本文程序运行的结果:

main.xml的源码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_height="fill_parent" android:layout_width="fill_parent">  
  4.     <LinearLayout android:layout_height="wrap_content"  
  5.         android:layout_width="fill_parent" android:orientation="vertical"  
  6.         android:layout_gravity="top">  
  7.         <LinearLayout android:orientation="horizontal"  
  8.             android:layout_gravity="center_horizontal" android:layout_marginTop="4.0dip"  
  9.             android:layout_height="wrap_content" android:layout_width="wrap_content">  
  10.             <Button android:layout_width="wrap_content"  
  11.                 android:layout_height="wrap_content" android:id="@+id/btnPlayUrl"  
  12.                 android:text="播放网络音频"></Button>  
  13.             <Button android:layout_height="wrap_content" android:id="@+id/btnPause"  
  14.                 android:text="暂停" android:layout_width="80dip"></Button>  
  15.             <Button android:layout_height="wrap_content"  
  16.                 android:layout_width="80dip" android:text="停止" android:id="@+id/btnStop"></Button>  
  17.         </LinearLayout>  
  18.         <LinearLayout android:orientation="horizontal"  
  19.             android:layout_width="fill_parent" android:layout_height="wrap_content"  
  20.             android:layout_marginBottom="20dip">  
  21.             <SeekBar android:paddingRight="10dip" android:layout_gravity="center_vertical"  
  22.                 android:paddingLeft="10dip" android:layout_weight="1.0"  
  23.                 android:layout_height="wrap_content" android:layout_width="wrap_content"  
  24.                 android:id="@+id/skbProgress" 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值