【发布时间】:2023-03-24 20:10:01
【问题描述】:
我正在尝试创建一个音乐流媒体应用。 到目前为止,它工作得很好。 我正在使用
MediaPlayer.create(thisContext, Uri.parse(PATH_TO_STREAM));
准备无限流(24x7 mp3 流)的便捷方法。 在这个调用中它只挂了几秒钟,我巧妙地将它塞进了我的 startPlaying() 方法中。 直到流开始播放后,该按钮才会显示它被点击,所以起初用户会想知道他们是否点击了按钮或错过了按钮。 因此,我想更新“等待...”或“缓冲”等按钮旁边的 TextView 标签,然后在流启动后将其清除,以便用户知道他们按下了 OK 按钮。 即使我在调试中逐步完成,标签直到 onClick 完成后才会更新。我可以注释掉清除标签文本的最后一行,并且可以看到它设置为“缓冲...”。但只有在它退出 onClick 之后。这是使用媒体播放器 create() 方法的限制吗?
final Button startbutton = (Button) findViewById(R.id.Button01);
this.tvBuffering = (TextView) findViewById(R.id.tvBuffering);
startbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
tvBuffering.setText("Buffering...");
//do something like invalidate() here??
startPlaying(); //blocks here for a few seconds to buffer then plays.
tvBuffering.setText(" "); //clear the text since it's playing by now.
}
});
【问题讨论】:
标签: android audio onclick media-player buffering