List of usage examples for android.support.v4.media MediaMetadataCompat METADATA_KEY_WRITER
String METADATA_KEY_WRITER
To view the source code for android.support.v4.media MediaMetadataCompat METADATA_KEY_WRITER.
Click Source Link
From source file:com.murati.oszk.audiobook.model.RemoteJSONSource.java
protected MediaMetadataCompat buildFromJSON(JSONObject json, String basePath) throws JSONException { String writer = json.getString(JSON_WRITER); String ebook = json.getString(JSON_EBOOK_TITLE); String title = json.getString(JSON_TRACK_TITLE); int trackNumber = json.getInt(JSON_TRACK_NUMBER); String genre = json.getString(JSON_GENRE); String source = json.getString(JSON_SOURCE); String iconUrl = json.getString(JSON_IMAGE); int totalTrackCount = json.getInt(JSON_TOTAL_TRACK_COUNT); int duration = json.getInt(JSON_DURATION) * 1000; // ms LogHelper.d(TAG, "Loaded tracks: ", json); // Media is stored relative to JSON file if (!source.startsWith("http")) { source = basePath + source;//from w ww . j a v a 2 s.c om } if (!iconUrl.startsWith("http")) { iconUrl = basePath + iconUrl; } // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. String id = String.valueOf(source.hashCode()); // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. //noinspection ResourceType // Skip faulty ones if (ebook == null || title == null || ebook.trim().length() * title.trim().length() == 0) { LogHelper.e(TAG, "Error processing JSON: " + json.toString()); return null; } // Fix writer if (writer == null || writer.trim().length() == 0) { if (title.contains(":")) { writer = title.split(":")[0]; } else { writer = "Ismeretlen szerz"; //TODO: resource } } //Fix title TODO: Strip from API ebook = ebook.replace(""", ""); ebook = ebook.replace("\"", ""); title = title.replace(""", "\""); return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, ebook) .putString(MediaMetadataCompat.METADATA_KEY_WRITER, writer) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); }
From source file:com.murati.oszk.audiobook.model.MusicProvider.java
public Iterable<String> getEbooksByQueryString(String query) { if (mCurrentState != State.INITIALIZED) { return Collections.emptyList(); }/*from w ww .ja v a2 s . c o m*/ TreeSet<String> sortedEbookTitles = new TreeSet<String>(); //TODO: Handle accents query = query.toLowerCase(Locale.US); for (MutableMediaMetadata track : mTrackListById.values()) { String title = track.metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM); if (!sortedEbookTitles.contains(title)) { String search_fields = track.metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM) + "|" + track.metadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE) + "|" + track.metadata.getString(MediaMetadataCompat.METADATA_KEY_WRITER) + "|" + track.metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE); if (search_fields.toLowerCase(Locale.US).contains(query)) { sortedEbookTitles.add(title); } } } return sortedEbookTitles; }
From source file:com.murati.oszk.audiobook.model.MusicProvider.java
private synchronized void retrieveMedia() { try {//ww w . ja v a2 s. c o m if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; Iterator<MediaMetadataCompat> tracks = mSource.iterator(); mEbookListByGenre = new ConcurrentHashMap<>(); mEbookListByWriter = new ConcurrentHashMap<>(); while (tracks.hasNext()) { MediaMetadataCompat item = tracks.next(); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); MutableMediaMetadata m = new MutableMediaMetadata(musicId, item); mTrackListById.put(musicId, m); addMediaToCategory(m, MediaMetadataCompat.METADATA_KEY_GENRE, mEbookListByGenre); addMediaToCategory(m, MediaMetadataCompat.METADATA_KEY_WRITER, mEbookListByWriter); } Long startTime = System.currentTimeMillis(); Log.d(TAG, "Build catalog started at " + startTime.toString()); buildAlbumList(); Long endTime = System.currentTimeMillis(); Log.d(TAG, "Build catalog finished at " + endTime.toString()); Log.d(TAG, "Build time was: " + Long.toString(endTime - startTime)); mCurrentState = State.INITIALIZED; } } catch (Exception e) { LogHelper.e(e.getMessage()); } finally { if (mCurrentState != State.INITIALIZED) mCurrentState = State.NON_INITIALIZED; } }
From source file:com.murati.oszk.audiobook.model.MusicProvider.java
private MediaBrowserCompat.MediaItem createEbookItem(String ebook, Resources resources) { //TODO: canonize ebook mediaid and title conversion if (ebook.startsWith(MEDIA_ID_BY_EBOOK)) { ebook = getCategoryValueFromMediaID(ebook); }//from w ww .j av a 2 s . c o m MediaMetadataCompat metadata = getTracksByEbook(ebook).iterator().next(); MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(createMediaID(null, MEDIA_ID_BY_EBOOK, ebook)).setTitle(ebook) .setSubtitle(metadata.getString(MediaMetadataCompat.METADATA_KEY_WRITER)) //TODO: Fix Album art .setIconUri(Uri.parse(metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI))) //TODO: fix default image // .setIconBitmap(BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_books)) .build(); return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE); }
From source file:com.murati.oszk.audiobook.model.MusicProvider.java
private MediaBrowserCompat.MediaItem createEbookHeader(String ebook, Resources resources) { //TODO: canonize ebook mediaid and title conversion if (ebook.startsWith(MEDIA_ID_BY_EBOOK)) { ebook = getCategoryValueFromMediaID(ebook); }/*from w w w . j a v a2 s . co m*/ MediaMetadataCompat metadata = getTracksByEbook(ebook).iterator().next(); //TODO: fix header notation MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(createMediaID(MEDIA_ID_EBOOK_HEADER, MEDIA_ID_BY_EBOOK, ebook)).setTitle(ebook) .setSubtitle(metadata.getString(MediaMetadataCompat.METADATA_KEY_WRITER)) //TODO: Fix Album art .setIconUri(Uri.parse(metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI))) //TODO: fix default image // .setIconBitmap(BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_books)) .build(); return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE); }