private void populateMoreInfoFromItem() { Res firstResource = content.getFirstResource(); this.resourceUri = firstResource.getValue(); this.mimeType = firstResource.getProtocolInfo().getContentFormatMimeType().toString(); this.subtitle = this.mimeType; setDuration(firstResource); if (getMusicItem()) { this.musicItem = new MusicTrack((Item) this.content); this.subtitle = this.musicItem.getFirstArtist().getName(); this.defaultResource = R.drawable.nocover_audio; this.type = "audio"; return; } if (isAudioItemOrDerivative()) { this.defaultResource = R.drawable.nocover_audio; this.type = "audio"; return; } if (isImageItemOrDerivative()) { this.defaultResource = R.drawable.ic_image_item; this.type = "image"; return; } if (isVideoItemOrDerivative()) { this.defaultResource = R.drawable.nocover_audio; this.type = "video"; return; } }
private void setDuration(Res firstResource) { if (isImageItemOrDerivative()) { return; } String[] time = firstResource.getDuration().split(".000"); this.duration = time[0]; }
@SuppressLint("SimpleDateFormat") public PlayableItem(Item item, int defaultDuration) { this.item = item; setTitle(item.getTitle()); Res resource = item.getFirstResource(); if (resource != null) { setUri(Uri.parse(resource.getValue())); String mimeType = resource.getProtocolInfo().getContentFormat(); if (mimeType == null || mimeType.equals("")) { String fileExtension = MimeTypeMap.getFileExtensionFromUrl(getUri().toString()); mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); } setMimeType(mimeType); // calculate duration long millis = defaultDuration; if (resource.getDuration() != null) { try { String[] tokens = resource.getDuration().split(":"); millis = (Long.valueOf(tokens[0]) * 3600 + Long.valueOf(tokens[1]) * 60 + Long.valueOf(tokens[2])) * 1000; Log.d( getClass().getName(), "resource.getDuration(): " + resource.getDuration() + " millis: " + millis); } catch (Exception e) { Log.d(getClass().getName(), "bad duration format", e); } } setDuration(millis); } }
public MediaStoreVideo( Cursor cursor, Uri mediaStoreUri, String parentId, String transientId, final URLBuilder urlBuilder) { PersonWithRole artist; PersonWithRole[] artists; this.mediaStoreId = cursor.getLong(ID); // Used as an persistent identifier this.mediaStoreUri = mediaStoreUri; setId(transientId); setParentID(parentId); setCreator(MediaDBContent.CREATOR); if (!cursor.isNull(ALBUM)) { // unused } if (!cursor.isNull(ARTIST)) { artist = new PersonWithRole( cursor.getString(ARTIST), CommonPartsOfMediaSnuggler.DEFAULT_ARTIST_ROLE_IF_UNKNOWN); artists = new PersonWithRole[1]; artists[0] = artist; setActors(artists); } else { artist = new PersonWithRole( CommonPartsOfMediaSnuggler.DEFAULT_ARTIST_NAME_IF_UNKNOWN, CommonPartsOfMediaSnuggler.DEFAULT_ARTIST_ROLE_IF_UNKNOWN); artists = new PersonWithRole[1]; artists[0] = artist; setActors(artists); } if (!cursor.isNull(LANGUAGE)) { setLanguage(cursor.getString(LANGUAGE)); } if (!cursor.isNull(DESCRIPTION)) { setDescription(cursor.getString(DESCRIPTION)); } if (!cursor.isNull(TITLE)) { setTitle(cursor.getString(TITLE)); } if (!cursor.isNull(CATEGORY)) { String[] categories = new String[1]; categories[0] = cursor.getString(CATEGORY); setGenres(categories); } if (!cursor.isNull(DURATION)) { this.duration = cursor.getLong(DURATION); } if (!cursor.isNull(MIME_TYPE)) { this.mimeType = MimeType.valueOf(cursor.getString(MIME_TYPE)); } else { this.mimeType = MimeType.valueOf(CommonPartsOfMediaSnuggler.MEDIA_VIDEO_DEFAULT_MIME_TYPE_IF_NOT_FOUND); } if (!cursor.isNull(SIZE)) { this.sizeInBytes = cursor.getInt(SIZE); } Res resource = new Res() { @Override public String getValue() { return urlBuilder.getURL(MediaStoreVideo.this); } }; resource.setProtocolInfo(new ProtocolInfo(mimeType)); resource.setDuration(Long.toString(duration)); resource.setSize(sizeInBytes); addResource(resource); LOGGER.info("Added resource."); }