当前位置: 首页 > news >正文

建设银行网站修改预留手机号上海装饰公司网站建设

建设银行网站修改预留手机号,上海装饰公司网站建设,南昌做seo的公司有哪些,企业移动网站品牌在项目中,有时候遇到要求,点击播放下一曲无法播放的问题。明明调用了start()方法了,为什么还是不行呢。 以下是我的代码 mediaPlayer=new MediaPlayer(); mediaPlayer.setDataSource(url[0]); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.pr…

在项目中,有时候遇到要求,点击播放下一曲无法播放的问题。明明调用了start()方法了,为什么还是不行呢。

以下是我的代码

mediaPlayer=new MediaPlayer();
mediaPlayer.setDataSource(url[0]);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();
mediaPlayer.start();

相信大家都懂这段代码了吧,mediaPlayer.prepareAsync();是为了异步加载网络数据,如果不这样可能app直接卡死掉。如果上面有报错记得try、catch。

后面想到了异步,那么可能是不及时的,比如说mediaPlayer.prepareAsync();刚开始是没任何东西的,可能需要延迟个几秒或毫秒才会得以加载网络的数据。那这个时候再执行mediaPlayer.start();肯定是没有播放的。后面想到了休眠,没错就是这么简单,将代码改成了

mediaPlayer=new MediaPlayer();
mediaPlayer.setDataSource(url[0]);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();
new Thread(new Runnable() {@Overridepublic void run() {try {Thread.sleep(2000);mediaPlayer.start();}catch (Exception e){}}
}).start();

问题得以解决。

贴上全部代码,app界面如图:

播放java文件

package com.wt.authenticwineunion.page.buys.activity;import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;import com.free.statuslayout.manager.StatusLayoutManager;
import com.wt.authenticwineunion.R;
import com.wt.authenticwineunion.base.BaseActivity;
import com.wt.authenticwineunion.base.BasePresenter;
import com.wt.authenticwineunion.util.ToastUtil;
import com.wt.authenticwineunion.widget.TitleView;import butterknife.BindView;
import butterknife.OnClick;
/*** 将音频以数组的格式返回过来,然后将他们进行下一首* */
public class PlayAudio2Activity extends BaseActivity {@BindView(R.id.title_view)TitleView titleView;@BindView(R.id.user_img)ImageView userImg;@BindView(R.id.title)TextView title;@BindView(R.id.title2)TextView title2;@BindView(R.id.new_time)TextView newTime;@BindView(R.id.all_time)TextView allTime;@BindView(R.id.progress)ProgressBar progress;@BindView(R.id.tui)ImageView tui;@BindView(R.id.last)ImageView last;@BindView(R.id.play)ImageView play;@BindView(R.id.next)ImageView next;@BindView(R.id.jin)ImageView jin;@BindView(R.id.content)TextView content;@BindView(R.id.toComment)TextView toComment;@BindView(R.id.number1)TextView number1;@BindView(R.id.pinlun)LinearLayout pinlun;@BindView(R.id.number2)TextView number2;@BindView(R.id.like)LinearLayout like;@BindView(R.id.fenxiang)LinearLayout fenxiang;private MediaPlayer mediaPlayer;private int w=0;private String url[]={"http://sc1.111ttt.cn:8282/2018/1/03m/13/396131232171.m4a?tflag=1546606800&pin=97bb2268ae26c20fe093fd5b0f04be80#.mp3","http://sc1.111ttt.cn:8282/2018/1/03m/13/396131226156.m4a?tflag=1546606800&pin=97bb2268ae26c20fe093fd5b0f04be80#.mp3","http://sc1.111ttt.cn:8282/2017/1/05m/09/298092035545.m4a?tflag=1546606800&pin=97bb2268ae26c20fe093fd5b0f04be80#.mp3"};@Overrideprotected void initStatusLayout() {statusLayoutManager = StatusLayoutManager.newBuilder(this).contentView(R.layout.activity_play_audio2).loadingView(R.layout.loading_layout).build();statusLayoutManager.showContent();}@Overridepublic void initView(Bundle bundle) {try {mediaPlayer=new MediaPlayer();mediaPlayer.setDataSource(url[0]);mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);mediaPlayer.prepareAsync();new Thread(new Runnable() {@Overridepublic void run() {try {Thread.sleep(2000);mediaPlayer.start();}catch (Exception e){}}}).start();
//            mediaPlayer.reset();}catch (Exception e){
http://www.yayakq.cn/news/612539/

相关文章:

  • 中国网站有哪些公司网页游戏交易平台有哪些
  • 网站培训视频重庆最近的新闻大事10条
  • 苏州网站建设哪家效果好桐城网站定制
  • 做百度网站需要多少钱建导航网站
  • 一站式媒体发布平台申请个人网站和企业官网有什么不同
  • 网站建设要注意那些问题南充外贸网站建设
  • 电子商务如何设计网站建设用ps怎么做网站效果图
  • 扬州市开发区建设局网站首页罗定市城乡建设局网站
  • 始兴县建设局网站欧洲网站设计
  • 模板网站会影响网站优化吗易语言如何做网站
  • 做磨毛布内销哪个网站比较好网站开发产品描述
  • 新绛网站建设建设了网站怎么管理
  • 苏州知名网站制作设计2017 wordpress宽屏主题
  • 西安 网站开发网站建设是否属于技术合同
  • f式布局网站手机创新网站
  • 网站建设方案书人员资金安排做一个网站后期维护需要做什么
  • 落实网站建设培训班精神百度推广官网网站
  • 有没有专门做建材的网站网页设计个人实训报告
  • 个人网站设计与实现源码网站建设分前端和后台吗
  • 怎么做平台网站安卓app开发实例教程
  • 产品网络推广seo自动推广工具
  • 古风自己做头像的网站做守望先锋h的网站
  • 做网站和APP需要注册公司吗域名可以免费注册码
  • 网站建设数据处理购物网站,购物车界面如何做
  • 单页网站建设教程wordpress文件上传位置
  • 城市维护建设税在哪个网站申报有没有做产品团购的网站
  • 石家庄市官方网站这么攻击网站
  • 泉州中小企业网站制作网站手机版下悬浮条怎么做
  • 如何做营销型网站公众号怎么制作链接
  • 如何建设学校门户网站深圳建设网站和公众号