[英]Audio playback using Android's own player
I would like to know how I can android's own player is activated at the time of pressing a button, I have tried but when I press the button the application is destroyed.我想知道如何在按下按钮时激活android自己的播放器,我试过但是当我按下按钮时应用程序被破坏。
This is the location of my mp3 file (Internal Storage / Download / Audio.mp3)这是我的 mp3 文件的位置(内部存储/下载/Audio.mp3)
alsoI have added this in the manifest:我也在清单中添加了这个:
<android:name="android.permission.READ_EXTERNAL_STORAGE"/>
My code我的代码
button1.setOnClickListener {
button1.setOnClickListener {
val audioDirPath = File(getFilesDir(), "Download")
audioDirPath.mkdir()
val file = File(audioDirPath, "audionline.mp3")
val contentUri = getUriForFile(this, "com.example.fileprovider", file)
val intent = Intent(Intent.ACTION_VIEW)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent)
}
}
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(intent)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.