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

网站中插入地图百度推广怎么注册账号

网站中插入地图,百度推广怎么注册账号,苏州建设培训中心网站,做软装什么网站可以在项目中,有时候遇到要求,点击播放下一曲无法播放的问题。明明调用了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.ds6.com.cn/news/113675.html

相关文章:

  • 游族网络公司最新消息北京网站优化步骤
  • 青岛企业展厅设计公司郑州技术支持seo
  • 政府电子网站建设解决方案网站友情链接是什么
  • 网站中的实名身份证验证怎么做360搜索优化
  • 潍坊专业网站建设公司百度收录查询工具
  • 昆明seo网站排名运营商推广5g技术
  • 二手商品交易网站开发seo优化靠谱吗
  • 网站开发的工作流程外包推广服务
  • wordpress 如何编辑器seo的基础优化
  • 扬州公司做网站公司个人博客网站怎么做
  • 建设银行管方网站30条新闻摘抄
  • 网站详情页艺术字怎么做的百度推广价格价目表
  • 西安高校定制网站建设公司推荐官方app下载安装
  • 流浪猫狗救助网站开发设计网站收录申请
  • 做电商网站必需知道qc企业推广的网站
  • 开发公司购买的游乐设备计入什么科目重庆seo俱乐部
  • 做网站建设与推广企业无锡营销型网站建设
  • 合肥优化排名推广重庆seo技术
  • 自建网站和租用空间网站代运营电商公司排行榜
  • 衡阳的网站建设网络营销推广微信hyhyk1效果好
  • 做市级网站需要什么意思百度快照优化排名怎么做
  • 怎么做送餐网站朝阳seo排名优化培训
  • 做网站不用服务器吗站长之家论坛
  • 免费海报制作网站郑州seo服务技术
  • 贵阳做网站的大公司持续优化完善防控措施
  • 网站免费优化海外黄冈网站推广
  • 做公司网站找谁产品推广平台
  • wordpress seo tdk英文seo是什么
  • 网站优化哈尔滨网络优化推广公司
  • 担路网提供网站建设整合营销