How would I write this intent in b4a?

vb1992

Well-Known Member
Licensed User
Longtime User
I wanted to get the Artist and Song name data from an MP3
(I added some links that could possibly help.)


Intent Intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse("sdcard/song.mp3");
Intent.setDataAndType(data,"audio/mp3");
Try {
StartActivity(Intent);
} Catch (ActivityNotFoundException e) {
e.printStackTrace();
}


B4a?

Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW,UriStr)
StartActivity(Intent1)



possible ref:

MediaMetadataRetriever | Android Developers

MediaStore | Android Developers


B4X:
 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename))); 

 File k = new File(path, filename);   
 ContentValues values = new ContentValues();   
 values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());   
 values.put(MediaStore.MediaColumns.TITLE, songTitle);   
 values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");   
 values.put(MediaStore.Audio.Media.ARTIST, "six3six");   
 values.put(MediaStore.Audio.Media.IS_RINGTONE, true);   
 values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);   
 values.put(MediaStore.Audio.Media.IS_ALARM, true);   
 values.put(MediaStore.Audio.Media.IS_MUSIC, false);    

 //Insert it into the database
 this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);

 return true; 
}
MyID3: a Java ID3 Tag Library


AsyncStreams Tutorial for MediaPlayerStream (mp3 stream)
 
Last edited:

vb1992

Well-Known Member
Licensed User
Longtime User
more reference....


B4X:
package pete.android.study;

import android.app.Activity;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView tvMain = (TextView)findViewById(R.id.tvMain);
        // load data file
        MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
        metaRetriever.setDataSource("/sdcard/music.mp3");

        String out = "";
        // get mp3 info
        out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
        out += "\n";
        out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
        out += "\n";
        out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
        out += "\n";
        out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
        out += "\n";
        // convert duration to minute:seconds
        String duration = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
        long dur = Integer.parseInt(duration);
        String seconds = String.valueOf(dur % 60);
        String minutes = String.valueOf(dur / 60000);
        out += "Length: [ " + minutes + "m" + seconds + "s ]\n";

        // close object
        metaRetriever.release();
        // display output
        tvMain.setText(out);
    }
}
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…