class MyMusicSoundsPlayer { private var mplayer:MediaPlayer? private var source:String="" constructor(){ mplayer=MediaPlayer() } fun play(name:String,loop:Boolean){ mplayer?.apply { if((source == name) && isPlaying()) { return } stop() reset() } source=name val filename=MyApplication.appCachePath+ source if (-1L==MyFileUtil.fileIsExists(filename)) { val mr=MySQLite.readOneBLOBbyIdStr(source) if(mr.ret) { //大文件无法读取 MyFileUtil.saveByteArrayToFile(mr.dataBOLB, filename) }else return } try { mplayer?.apply { //reset() //must reset setDataSource(filename) isLooping=loop setVolume(0.3F,0.5F) prepareAsync()
安卓开发安全有效启动停止Mediaplayer播放(kotlin语言)
于 2023-03-27 16:02:41 首次发布