alexfugui / voiceplayer Goto Github PK
View Code? Open in Web Editor NEWAndroid 安卓 播放网络音频 支持缓存
License: Apache License 2.0
Android 安卓 播放网络音频 支持缓存
License: Apache License 2.0
如题
//预加载,会下载文件下来
VoiceDownloadUtil.instance()
.download(data, new OnDownloadListener() {
@Override
public void onDownloadSuccess(File file) {
button.setText("加载完成");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mOnViewClickListener.onViewClick(button, position);
}
});
}
@Override
public void onDownloading(int progress) {
button.setText(progress + "%");
}
@Override
public void onDownloadFailed(Exception e) {
button.setText("加载失败" + e.toString());
}
});
上述代码,在 onDownloading(int progress) 方法里设置进度或文字会报如下错误
例如使用 textview,设置文字显示进度会报错,使用 progesssbar也会报错
2021-07-17 09:16:58.495 29805-29865/com.jmusic E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.jmusic, PID: 29805
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7194)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1142)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:5205)
at android.view.View.invalidateInternal(View.java:13781)
at android.view.View.invalidate(View.java:13745)
at android.view.View.invalidate(View.java:13729)
at android.widget.TextView.checkForRelayout(TextView.java:7486)
at android.widget.TextView.setText(TextView.java:4562)
at android.widget.TextView.setText(TextView.java:4414)
at android.widget.TextView.setText(TextView.java:4389)
at com.jmusic.activity.PlayMusicActivity$3.onDownloading(PlayMusicActivity.java:119)
at com.alex.voice.netWork.VoiceDownloadUtil.writeFile(VoiceDownloadUtil.java:123)
at com.alex.voice.netWork.VoiceDownloadUtil.access$000(VoiceDownloadUtil.java:30)
at com.alex.voice.netWork.VoiceDownloadUtil$1.onResponse(VoiceDownloadUtil.java:75)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
怎么监听播放进度
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.