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; } }
@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); } }