5

मैं एंड्रॉइड डिवाइस में कौन सा संगीत ऐप संगीत चला रहा हूं, इसकी जांच कैसे करूं?यह जांचने के लिए कि किस संगीत ऐप से संगीत खेला जा रहा है?

ऑडियोमैनेजर का उपयोग करके, हम जांच सकते हैं कि संगीत खेला जा रहा है या नहीं। लेकिन यह संगीत ऐप का विवरण प्रदान नहीं करता है, जिससे इसे खेला जा रहा है।

AudioManager बजे = (AudioManager) this.getSystemService (Context.AUDIO_SERVICE);

am.isMusicActive() रिटर्न सच अगर संगीत उपकरण में खेला जाता है। लेकिन मैं संगीत ऐप का नाम चाहता हूं जिसमें से इसे खेला जा रहा है।

संदर्भ:

How do you check if music is playing by using a broadcast receiver?

Android development : To find out which app is playing music currently

उदाहरण के लिए, अगर मैं Google संगीत प्लेयर से संगीत खेलते हैं। तो मुझे संगीत ऐप नाम "Google म्यूजिक प्लेयर" के रूप में प्राप्त करने में सक्षम होना चाहिए।

इसके लिए कोई भी जवाब की सराहना की जाएगी। धन्यवाद!

उत्तर

0

इस प्रयास करें वर्तमान में ट्रैक के फ़ाइल पथ खेलने पाने के लिए:

public Cursor query(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, int limit) { 
    try { 
     ContentResolver resolver = context.getContentResolver(); 
     if (resolver == null) return null; 
     if (limit > 0) uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build(); 
     return resolver.query(uri, projection, selection, selectionArgs, sortOrder); 
    } catch (UnsupportedOperationException ex) { return null; } 
} 
private BroadcastReceiver mReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     String path = intent.getStringExtra("track").replaceAll("'","''"); 
     Cursor c = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
       new String[] { MediaStore.Audio.Media.DATA }, MediaStore.Audio.Media.TITLE + "='" + path + "'", 
       null, null, 0); 
     try { 
      if (c == null || c.getCount() == 0) return; 
      int size = c.getCount(); 
      if (size != 1) return; 
      c.moveToNext(); 

      // Here's the song path 
      String songPath = c.getString(0); 
      Log.d("ROAST_APP", "" + songPath); 
     } finally { 
      if (c != null) c.close(); 
     } 
    } 
}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    IntentFilter iF = new IntentFilter(); 
    iF.addAction("com.android.music.metachanged"); 
    iF.addAction("com.android.music.playstatechanged"); 
    iF.addAction("com.android.music.playbackcomplete"); 
    iF.addAction("com.android.music.queuechanged"); 
    registerReceiver(mReceiver, iF); 
} 

सूत्रों:
Track info of currently playing music
Needletagger

संबंधित मुद्दे