首页 文章

代号为Mediaplayer的一个滑块

提问于
浏览
1

我正在尝试以代号创建一个音乐播放应用程序,我在向媒体播放器添加滑块时遇到问题 . 当应用程序运行时显示滑块但是在播放文件时它没有显示进度 . 这是代码我用来添加自定义播放和暂停按钮以及滑块

try {
     video = MediaManager.createMedia(sample_url, false);
     myslider.setMinValue(0);
     myslider.setMaxValue(video.getDuration()/1000);
     myslider.setIncrements(1);
     myslider.addDataChangedListener(new DataChangedListener(){
         @Override
         public void dataChanged(int type, int index) {
            video.setTime(myslider.getProgress()*1000);

         }
     });


      } catch (Exception err) {
        Log.e(err);
        ToastBar.Status status = ToastBar.getInstance().createStatus();
           status.setMessage(" error loading sample file");
           status.show();
           status.clear();

    }
     sample.add(BorderLayout.SOUTH,myslider);

    play.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent evt) {
           //To change body of generated methods, choose Tools | Templates.
           //StreamFile(songDetails,sample_url);

          if(!video.isPlaying()){

          video.play();
           sample.removeComponent(play);
           sample.revalidate();
           sample.add(BorderLayout.WEST,pause);
           sample.revalidate();


          }

        }
    });
    pause.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent evt) {
            //To change body of generated methods, choose Tools | Templates.
            if(video.isPlaying()){
            video.pause();
            sample.removeComponent(pause);
            sample.revalidate();
           sample.add(BorderLayout.WEST,play);
           sample.revalidate();

            }
        }
    });

1 回答

  • 0

    我没有看到将侦听器绑定到媒体的代码,并且只将滑块的值设置为将侦听器绑定到滑块并设置媒体值的代码 . 请注意,您可以使用本机播放小部件,请参阅:https://www.codenameone.com/blog/media-controls-print-developer-guide.html

    您需要使用媒体的当前播放时间定期更新滑块,例如使用 UITimer 更新当前滑块值 . 确保这不会让你进入循环 .

相关问题