4

I'm facing a weird crash in the Samsung device only.

See the stacktrace below,

Fatal Exception: com.pilabs.musicplayer.tageditor.TagEditFailedException: Tag edit failed : Changing volume from /storage/3964-3431/Music/Bujji-MassTamilan.io.mp3 to /storage/emulated/0/Music/.pending-1608532169-Bujji-MassTamilan.io.mp3 not allowed
   at com.pilabs.musicplayer.tageditor.PiTagEditor.handleException(PiTagEditor.java:643)
   at com.pilabs.musicplayer.tageditor.PiTagEditor.editTrackTagInfoImpl(PiTagEditor.java:217)
   at com.pilabs.musicplayer.tageditor.PiTagEditor.access$setUiCallback$p(PiTagEditor.java:37)
   at com.pilabs.musicplayer.tageditor.PiTagEditor$editTrackTagInfo$1.invokeSuspend(PiTagEditor.java:79)
   at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
   at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:238)
   at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:594)
   at kotlinx.coroutines.scheduling.CoroutineScheduler.access$createdWorkers(CoroutineScheduler.java:60)
   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:742)

Where TagEditFailedException is my own Written Exception. Actual exception being,

java.lang.IllegalArgumentException: Changing volume from /storage/3964-3431/Music/Bujji-MassTamilan.io.mp3 to /storage/emulated/0/Music/.pending-1608532169-Bujji-MassTamilan.io.mp3 not allowed

More than anything, look for

Changing volume from /storage/3964-3431/Music/Bujji-MassTamilan.io.mp3 to /storage/emulated/0/Music/.pending-1608532169-Bujji-MassTamilan.io.mp3 not allowed

I debugged the code and found that the app is crashing when updating IS_PENDING before updating other metadata.

private fun updateNameChangesInAndroidDb(application: Application, editTrackTagInfo: EditTrackTagInfo) {

    val uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            editTrackTagInfo.trackId.toLong())

    val contentValues = ContentValues()

    if (hasQ()) {
        contentValues.put(MediaStore.Audio.Media.IS_PENDING, 1)
        application.contentResolver.update(uri, contentValues, null, null)
    }

    contentValues.clear()
            
    if (hasQ()) 
       contentValues.put(MediaStore.Audio.Media.IS_PENDING, 0)

    with(editTrackTagInfo) {
        title?.let { it -> contentValues.put(MediaStore.Audio.Media.TITLE, it) }
        album?.let { it -> contentValues.put(MediaStore.Audio.Media.ALBUM, it) }
        artist?.let { it -> contentValues.put(MediaStore.Audio.Media.ARTIST, it) }
    }

    val rowsUpdated = application.contentResolver.update(uri, contentValues,
            null, null)

app crashes at

application.contentResolver.update(uri, contentValues, null, null)

while updating IS_PENDING to 1 in

if (hasQ()) {
    contentValues.put(MediaStore.Audio.Media.IS_PENDING, 1)
    application.contentResolver.update(uri, contentValues, null, null)
}

I don't understand why updating is_pending would change the volume from SD_Card to internal storage (/storage/emulated/0...).

  • App crashes only on Android 11 devices. That too on Samsung device only. That too when the track I'm trying to edit is from SD-CARD.
  • I have tried with Android 11 pixel devices and it works fine.
  • The track which I'm trying to edit is in SdCard at location

/storage/3964-3431/Music/Bujji-MassTamilan.mp3

  • I don't understand why while updating IS_PENDING to 1 in samsung android 11 device, root location of media is changing to internal storage

/storage/emulated/0/Music/...

Summary - App crashes only in Android 11 Samsung device when media-file is from SD-Card.

Abhishek Kumar
  • 4,532
  • 5
  • 31
  • 53
  • You do that all without any code? – blackapps Dec 14 '20 at 13:00
  • @blackapps check the updated post. – Abhishek Kumar Dec 14 '20 at 13:49
  • Do not construct an uri with ContentUris.withAppendedId but use the uri you got earlier with .insert(). The least you could do is check if they are the same. – blackapps Dec 14 '20 at 14:18
  • @blackapps which .insert() are you talking about? Media is already in the device and I'm getting all the media using MediaStore and then using _ID trying to get uri. – Abhishek Kumar Dec 14 '20 at 14:31
  • `Summary - App crashes` You could better name the exception as it is more informative. And if you catch that exception your app will not crash but the exception is still thrown. – blackapps Dec 14 '20 at 15:57
  • `TagEditFailedException` Never heard of. – blackapps Dec 14 '20 at 15:58
  • @blackapps java.lang.IllegalArgumentException: Changing volume from /storage/3964-3431/Music/Bujji-MassTamilan.io.mp3 to /storage/emulated/0/Music/.pending-1608532169-Bujji-MassTamilan.io.mp3 not allowed is the exception as updated in the question itself – Abhishek Kumar Dec 14 '20 at 16:05
  • In this way we have nothing to reproduce i think. Are you shure on other devices you can rename files on removable media? – blackapps Dec 14 '20 at 16:24
  • @blackapps yes. issue is with samsung running android 11 only (even here when media is in removable storage). In other devices its working fine. And in samsung it's happening all the time (easily reproducible there) – Abhishek Kumar Dec 14 '20 at 16:26

0 Answers0