trying to do something like a player. Plays. But I can not extract any information about the file. On the English forum there are examples but with uri and the MediaMetadataRetriever class in which I can not find a suitable constructor that accepts a media file. How do I read info about the audio that is playing? the service itself that loses me looks like this.

public class service extends Service{ static String str; static int pos; MediaPlayer media = new MediaPlayer(); MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever(); @Override public IBinder onBind(Intent arg0) {return null;} @Override public void onCreate() { super.onCreate(); media = MediaPlayer.create(this,R.raw.arena); metaRetriever.setDataSource(getPackageResourcePath()); str = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);// никакую инфу не дает media.start(); } @Override public void onDestroy() { media.stop(); media=null; super.onDestroy();} } 

    1 answer 1

    I dare to assume that in the setDataSource(String path) method setDataSource(String path) you pass not exactly what you need. Try passing there directly to the media file.

    Example

    Upd . Try this:

      Uri mediaPath = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.arena); metaRetriever.setDataSource(getApplicationContext(), mediaPath); String artist = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); 
    • I have problems with the path ... I don’t know how to set it up. The file is located in the res / raw folder. but from where to lead this path is not clear. Found an example of the type - "android.resource: //" + getPackageName () + "/" + R.raw.arena ... but it doesn't work either - PeteGr
    • @PeteGr, added an example to the answer. - s8am
    • Yes, it worked !! - PeteGr
    • @PeteGr, if you are provided with an exhaustive answer, please mark it as accepted (tick box to the left of the answer). - aleksandr barakin