螺纹使用在Android媒体播放器搜索栏 [英] Thread using for seekbar on android mediaplayer

查看:102
本文介绍了螺纹使用在Android媒体播放器搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个线程,将检查乐曲位置每秒移动根据歌曲的位置搜索栏。我使用的打击code这是玩只有两个songs..then它从我的applicatin敬而远之

 公共类值存取工具MediaPlayer.On preparedListener
         {            在prepared(MediaPlayer的MPS)公共无效{
                // TODO自动生成方法存根
                seekbar.setMax(mp.getDuration());
                 新主题(新的Runnable接口(){                  公共无效的run(){
                          而(MP =空&安培;!&安培; mp.getCurrentPosition()< mp.getDuration())
                          {
                              seekbar.setProgress(mp.getCurrentPosition());
                              消息味精=新的Message();
                              INT米利斯= mp.getCurrentPosition();                              msg.obj =米利斯/ 1000;                               尝试{
                                   视频下载(100);
                               }
                               赶上(InterruptedException的E){
                                  e.printStackTrace();
                               }
                          }
                  }
          })。开始();
            }


解决方案

下面的编码工作正常

 公共类SETP实现MediaPlayer.On $ P $ {pparedListener    在prepared(MediaPlayer的MPS)公共无效{
        // TODO自动生成方法存根
        seekbar.setMax(mp.getDuration());
        的System.out.println(CURPOS+ mp.getCurrentPosition());
        新主题(新的Runnable接口(){
            公共无效的run(){
                尝试{
                    而(熔点=空&放大器;!&放大器; mp.getCurrentPosition()&所述; mp.getDuration()){
                        seekbar.setProgress(mp.getCurrentPosition());
                        消息味精=新的Message();
                        INT米利斯= mp.getCurrentPosition();                        msg.obj =米利斯/ 1000;                        尝试{
                            视频下载(100);
                        }赶上(InterruptedException的E){
                            e.printStackTrace();
                            的System.out.println(中断exeption+ E);
                        }
                    } //结束时
                }赶上(例外五){
                    e.printStackTrace();
                    的System.out.println(我的异常+ E);
                }
            }
        })。开始();
    }
}

How to create a thread that will check the song position every second and move the seekbar based on the song position. i used the blow code it's play only two songs..then it's turn away from my applicatin

public class setp implements MediaPlayer.OnPreparedListener  
         {

            public void onPrepared(MediaPlayer mps) {
                // TODO Auto-generated method stub
                seekbar.setMax(mp.getDuration());
                 new Thread(new Runnable() {

                  public void run() {
                          while(mp!=null && mp.getCurrentPosition()<mp.getDuration())
                          {
                              seekbar.setProgress(mp.getCurrentPosition());
                              Message msg=new Message();
                              int millis = mp.getCurrentPosition();

                              msg.obj=millis/1000;

                               try {
                                   Thread.sleep(100);
                               } 
                               catch (InterruptedException e) {
                                  e.printStackTrace();
                               }
                          }
                  }
          }).start();
            }

解决方案

the below coding is working fine

public class setp implements MediaPlayer.OnPreparedListener {

    public void onPrepared(MediaPlayer mps) {
        // TODO Auto-generated method stub
        seekbar.setMax(mp.getDuration());
        System.out.println("curpos" + mp.getCurrentPosition());
        new Thread(new Runnable() {
            public void run() {
                try {
                    while (mp != null && mp.getCurrentPosition() < mp.getDuration()) {
                        seekbar.setProgress(mp.getCurrentPosition());
                        Message msg = new Message();
                        int millis = mp.getCurrentPosition();

                        msg.obj = millis / 1000;

                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                            System.out.println("interrupt exeption" + e);
                        }
                    } // end while
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("my Exception" + e);
                }
            }
        }).start();
    }
}

这篇关于螺纹使用在Android媒体播放器搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆