I am making Android application that displays contents that is copied from USB storage disk.
The problem is when USB storage disc is connected to device, Media Player onCompletion() is immediately called although movie now playing is not finished yet.
I want to fix this problem not to call onCompletion() when USB is connected.
Thanks in advance.
class PlayerViewModel(application: Application, repository: GCSRepository) : ViewModel(), USBDownloadListener,
MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
override fun onDownloadFinished(unusedFiles: MutableSet<String>) {
// some codes here...
}
override fun onCompletion(mp: MediaPlayer?) {
// some codes here...
}
}
class USBIOManager(context: Context) {
init {
registerReceiver(context)
}
private fun registerReceiver(context: Context) {
unRegisterReceiver(context)
mUsbReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// some codes here...
updateUSBFiles(context)
// some codes here...
}
}
}
private fun updateUSBFiles(context: Context) {
// some codes here...
downloadListener?.onDownloadFinished(existingInternalStorageFiles)
// some codes here...
}
interface USBDownloadListener {
fun onDownloadFinished(unusedFiles : MutableSet<String>)
}