Access ordered images and video in same Cursor

After lots of research and playing around with source code, I’m finally a bit more familiar with the Android filesystem. To get a single Cursor which can access information about both Images and Video I used the following: // Get relevant columns for use later. String[] projection = { MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.DATE_ADDED, MediaStore.Files.FileColumns.MEDIA_TYPE, MediaStore.Files.FileColumns.MIME_TYPE, MediaStore.Files.FileColumns.TITLE … Read more

How do you get/set media volume (not ringtone volume) in Android?

private AudioManager audio; Inside onCreate: audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); Override onKeyDown: @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; default: return false; } }

How to use JavaFX MediaPlayer correctly?

The problem is because you are trying to run JavaFX scene graph control outside of JavaFX Application thread. Run all JavaFX scene graph nodes inside the JavaFX application thread. You can start a JavaFX thread by extending JavaFX Application class and overriding the start() method. public class Main extends Application { @Override public void start(Stage … Read more

How to update the Android media database

Android has a cache of sorts that keeps track of media files. Try this: sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(“file://” + Environment.getExternalStorageDirectory()))); It makes the MediaScanner service run again, which should remove the deleted song from the device’s cache. You also need to add this permission to your AndroidManifest.xml: <intent-filter> <action android:name=”android.intent.action.MEDIA_MOUNTED” /> <data android:scheme=”file” /> </intent-filter>

Volume change listener?

Check out registerMediaButtonEventReceiver(ComponentName broadcastReceiver); Define a BroadcastReceiver that handles ACTION_MEDIA_BUTTON. The recieved intent includes a single extra field, EXTRA_KEY_EVENT, containing the key event that caused the broadcast. You can use this key event to get which key was pressed. EDIT: This is just a sample code. syntax errors may be there. // in onCreate of … Read more

@Media print css

If that is the exact structure of your html then this will work for you. @media print { nav, div > div:not(.to-print), div + div:not(.to-print) { display: none; } } /* So you can see the styles working on the elements you want to hide outside of print */ nav, div > div:not(.to-print), div + … Read more

Given an Android music playlist name, how can one find the songs in the playlist?

Here is a bit from my program: The gist is that you need the id for the playlist to grab the songs. Basically you can take my code and change the where statement to .NAME +” = ‘”+name+”‘”, private Cursor getPlaylists(String playlistId){ Cursor cursor = null; String[] projection1 = { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME }; cursor = … Read more

time length of an mp3 file

You can use pymad. It’s an external library, but don’t fall for the Not Invented Here trap. Any particular reason you don’t want any external libraries? import mad mf = mad.MadFile(“foo.mp3”) track_length_in_milliseconds = mf.total_time() Spotted here. — If you really don’t want to use an external library, have a look here and check out how … Read more

Android: save a file from an existing URI

Use this method, it works void savefile(URI sourceuri) { String sourceFilename= sourceuri.getPath(); String destinationFilename = android.os.Environment.getExternalStorageDirectory().getPath()+File.separatorChar+”abc.mp3″; BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(new FileInputStream(sourceFilename)); bos = new BufferedOutputStream(new FileOutputStream(destinationFilename, false)); byte[] buf = new byte[1024]; bis.read(buf); do { bos.write(buf); } while(bis.read(buf) != -1); } catch (IOException e) { … Read more