I want my app to get the MediaMetaData (song title/artist/album) of the currently playing audio. I can see this info being printed to logcat on my computer under updateMediaMetadata, so I'm trying to extract that info somehow.
EDIT: So logcat definitely is not the way to go for doing this, when I can make/detect MediaMetadata calls. I'm trying to make a new class that prints out the title of the currently playing MediaMetadata when I call a function but My code isn't compiling and I was wondering if it has something to do with how I set up my class? From what I understand of the documentation:
https://developer.android.com/reference/android/media/MediaMetadata
I'm trying to extend the class to utilize its functions like so:
package com.example.crisisapp;
import android.media.AudioAttributes;
import android.media.MediaMetadata;
import android.media.session.PlaybackState;
import android.os.Bundle;
import android.media.session.MediaSession.QueueItem;
import android.util.Log;
import android.os.Bundle;
import java.util.List;
public class MediaController extends android.media.MediaMetadata{
MediaController(Bundle bundle) {
super(bundle);
}
public void getMediaMetadata(){
Log.i("myTag", "inside getMediaMetadata()");
MediaMetadata mc = new MediaMetadata();
//String title = mc.getString("METADATA_KEY_TITLE");
//Log.i("myTag", "METADATA_KEY_TITLE = "+title);
}
}
And my MainActivity calls this function like so:
public void startTrackingMusic(View view) {
Log.i("myTag", "start of startTrackingMusic()");
MediaController mc = new MediaController();
final long NANOSEC_PER_SEC = 1000l*1000*1000;
long startTime = System.nanoTime();
while ((System.nanoTime()-startTime)< 2*60*NANOSEC_PER_SEC){
Log.i("myTag", "loop");
mc.getMediaMetadata();
}
Log.i("myTag", "end of startTrackingMusic()");
}
When I try to build my project it gives errors saying I cannot inherit from final MediaMetadata and so on:
What am I missing that needs to be done to declare MediaMetadata correctly and retrieve the Title string?