0

When I launch my application after upgrading from android 7 to 8.1 I noticed that it lost a lot of responsiveness.

When I'm trying to get songs from device memory I get a lot of errors like:

E/SEC_DRM_PLUGIN_Omafl: OmaPlugin::onOpenDecryptSession(fd)::Drm2IsDrmFileByExtFd::file is NOT DRM by extension

That works much slower than on the Android 7.

Code:

public ArrayList<Song> getSongList() {
    MediaMetadataRetriever metaRetriver = new MediaMetadataRetriever();
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
    ArrayList<Song> songList = new ArrayList<>();
    ContentResolver musicResolver = context.getContentResolver();
    Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor musicCursor = musicResolver.query(musicUri, null, selection, null, null);

    if (musicCursor != null && musicCursor.moveToFirst()) {
        int titleColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
        int idColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media._ID);
        int artistColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
        int durationColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
        int column_index = musicCursor.getColumnIndex(MediaStore.Audio.Media.DATA);

        do {
            long id = musicCursor.getLong(idColumn);
            String path = musicCursor.getString(column_index);
            String title = musicCursor.getString(titleColumn);
            String artist = musicCursor.getString(artistColumn);
            String duration = musicCursor.getString(durationColumn);

            try {
                metaRetriver.setDataSource(path);
                songList.add(new Song(id, title, artist, path, duration));
            }catch (Exception exc){}

        } while (musicCursor.moveToNext());
    }
    return songList;
}
Oktawian
  • 334
  • 1
  • 2
  • 16
  • Welcome to Stack Overflow, Oktawian. Please take the [tour](https://stackoverflow.com/tour) and read the help pages on how to ask questions here. Also note that links to github repositories aren't allowed here as the only reference, we need the actual code in question copied into the question itself. – Graham Dec 14 '18 at 23:04
  • @Graham - "What is wrong with my code" problems are not off-topic here ... under the right circumstances. But they are **definitely and explicitly** off-topic on CodeReview!! – Stephen C Dec 14 '18 at 23:05
  • Noted and edited my comment accordingly. – Graham Dec 14 '18 at 23:07
  • The prerequesite for them to be on-topic here is that there is sufficient code and other relevant information to allow diagnosis. Ideally, they should include an MCVE. – Stephen C Dec 14 '18 at 23:07
  • 1
    added tags `android-mediaplayer` and `android-drm`... because it appears related. however, an interface does nothing by itself and so that code is not a good example - profiling on Android 7.0 & 8.1 might be useful, in order to narrow down the scope of the question. – Martin Zeitler Dec 14 '18 at 23:18
  • Please read the article on [MCVE](https://stackoverflow.com/help/mcve), basically it means we need to see the Minimal amount of code required to reproduce the issue. You also said that you get a lot of errors like the one in your question, so technically you are asking "what do errors like this mean?" – Graham Dec 14 '18 at 23:24
  • It would probably be a great idea for you to do some debugging and figure out what part of your code is causing the error above, then post that as a new discrete question. – Graham Dec 14 '18 at 23:25
  • how `DRM` is working on Android is explained here: https://source.android.com/devices/drm#listeners - would suggest not loading /scanning the playlist synchronously on the main thread - because this is where is most likely start to get unresponsive. – Martin Zeitler Dec 14 '18 at 23:39

1 Answers1

0

I had to delete the one line of code that was causing the error when trying to get every single song from memory:

mediaMetadataRetriver.setDataSource(pathOfSong);

Hope it will help you.

Oktawian
  • 334
  • 1
  • 2
  • 16