MediaFacade


Source link: https://github.com/Drivemode/MediaFacade

MediaFacade

Facade modules for dealing with complicated MediaStore in a simple way.

Usage

Audio

Audio in MediaStore has several tables like Media, Artists, Albums, Playlists and Genres. MediaFacade provides easy accesses to those tables.

Albums

public class SampleActivity extends Activity {

private AudioFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor albums = null;
  try {

 albums = facade.album().fetchAlbum();

 // do whatever you like with the album metadata
  
}
 finally {

 if (albums != null)

albums.close();

  
}

}
 
}

Artists

public class SampleActivity extends Activity {

private AudioFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor artists = null;
  try {

 artists = facade.artist().fetchArtists();

 // do whatever you like with the album metadata
  
}
 finally {

 if (artists != null)

artists.close();

  
}

}
 
}

Genres

public class SampleActivity extends Activity {

private AudioFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor genres = null;
  try {

 genres = facade.genre().fetchGenres();

 // do whatever you like with the album metadata
  
}
 finally {

 if (genres != null)

genres.close();

  
}

}
 
}

Playlists

public class SampleActivity extends Activity {

private AudioFacade facade;
private EditText playlistName;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = AudioFacade.getInstance(this);

  Cursor playlists = null;
  try {

 playlists = facade.playlist().fetchGenres();

 // do whatever you like with the album metadata
  
}
 finally {

 if (playlists != null)

playlists.close();

  
}

}

 public void onNewPlaylistButtonClick(View v) {

  String name = playlistName.getText().toString();

  Uri uri = facade.playlist().createNew(name);

  // you can add music tracks with this uri

}
 
}

Image and Video

Image and Video have similar structure in their tables. One noteworthy concept is Bucket, which is kind of Album for images and/or videos. Image and Video have 2 columns ( BUCKET_ID and BUCKET_DISPLAY_NAME) for describing which bucket the image belongs to.

Bucket

Since there's no specific table that manages each buckets so you need to group by bucket when you query images/videos in SQL. ImageFacade and VideoFacade do grouping for you.

public class SampleActivity extends Activity {

private ImageFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = ImageFacade.getInstance(this);

  Cursor imageBuckets = null;
  try {

 imageBuckets = facade.bucket().fetch();

 if (imageBuckets == null)

return;

 while (imageBuckets.moveToNext()) {

long bucketId = imageBuckets.getLong(imageBuckets.getColumnIndex(MediaStore.Image.Media.BUCKET_ID));

// you can query images in the specific bucket with this bucketId

Cursor imagesInBucket = facade.image().fetchByBucket(bucketId);

// ...

 
}

  
}
 finally {

 if (imageBuckets != null)

imageBuckets.close();

  
}

}
 
}

Cursors

MediaFacade provides customized yet fully Android compatible Cursors for developers to access fields by just calling corresponding methods.

public class SampleActivity extends Activity {

private ImageFacade facade;
 @Override
protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// ...

facade = ImageFacade.getInstance(this);

  ImageCursor imageBuckets = null;
  try {

 imageBuckets = facade.bucket().fetch();

 if (imageBuckets == null)

return;

 while (imageBuckets.moveToNext()) {

long bucketId = imageBuckets.id();

// you can query images in the specific bucket with this bucketId

ImageCursor imagesInBucket = facade.image().fetchByBucket(bucketId);

// ...

 
}

  
}
 finally {

 if (imageBuckets != null)

imageBuckets.close();

  
}

}
 
}

We have following customized classes of Cursors.

  • MediaItemCursor
  • AlbumCursor
  • AlbumItemCursor
  • GenreCursor
  • GenreItemCursor
  • ArtistCursor
  • ArtistItemCursor
  • PlaylistCurosr
  • PlaylistItemCurosr
  • ImageCursor
  • VideoCursor

These Cursors are subclasses of Cursor so that you can use them with CursorAdapter and various Cursor API.

Download

Gradle:

compile 'com.drivemode:mediafacade-audio:0.1.0@aar' compile 'com.drivemode:mediafacade-image:0.1.0@aar' compile 'com.drivemode:mediafacade-video:0.1.0@aar' 

License

Apache v2

Copyright (C) 2016 Drivemode, Inc. All rights reserved.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

RxTasks for GMS.

A simple android library to easily implement social login into your android project.

Easily display the common items of an About Box in a modern Android Material Design way.

When triggered from a menu item, it will display the app name, icon and version, provide links to contact support, leave a review, share the app, go to other apps by the same company in the app store - as well as links to Facebook etc.

About Box is quickly configured with a set of (mostly) strings for the company name, twitter and Facebook accounts, website, and filenames to html files for help files, privacy policy etc.

RxJava1/2 for Android BroadcastReceiver.

Lib overrides android.support.v4.util.LruCache and uses code from article to measure size of objects in heap.

  • It is the superfast view to display contacts in RecyclerView with rich material design UI.
  • This view can be used as a contact picker using bottom sheet dialog and activity.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes