java new uri,Java URI.create方法代码示例

import java.net.URI; //导入方法依赖的package包/类

@Override

public DIDLObject browseMeta(YaaccContentDirectory contentDirectory,

String myId) {

Item result = null;

String[] projection = {MediaStore.Audio.Media._ID,

MediaStore.Audio.Media.DISPLAY_NAME,

MediaStore.Audio.Media.MIME_TYPE, MediaStore.Audio.Media.SIZE,

MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ALBUM_ID,

MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST,

MediaStore.Audio.Media.DURATION};

String selection = MediaStore.Audio.Media._ID + "=?";

String[] selectionArgs = new String[]{myId

.substring(ContentDirectoryIDs.MUSIC_ALL_TITLES_ITEM_PREFIX

.getId().length())};

Cursor mediaCursor = contentDirectory

.getContext()

.getContentResolver()

.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,

selection, selectionArgs, null);

if (mediaCursor != null) {

mediaCursor.moveToFirst();

String id = mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media._ID));

String name = mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));

Long size = Long.valueOf(mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.SIZE)));

String album = mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.ALBUM));

String albumId = mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));

String title = mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.TITLE));

String artist = mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.ARTIST));

String duration = mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.DURATION));

duration = contentDirectory.formatDuration(duration);

Log.d(getClass().getName(),

"Mimetype: "

+ mediaCursor.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.MIME_TYPE)));

MimeType mimeType = MimeType.valueOf(mediaCursor

.getString(mediaCursor

.getColumnIndex(MediaStore.Audio.Media.MIME_TYPE)));

// file parameter only needed for media players which decide

// the

// ability of playing a file by the file extension

String uri = getUriString(contentDirectory, id, mimeType);

URI albumArtUri = URI.create("http://"

+ contentDirectory.getIpAddress() + ":"

+ YaaccUpnpServerService.PORT + "/?album=" + albumId);

Res resource = new Res(mimeType, size, uri);

resource.setDuration(duration);

MusicTrack musicTrack = new MusicTrack(

ContentDirectoryIDs.MUSIC_ALL_TITLES_ITEM_PREFIX.getId()

+ id,

ContentDirectoryIDs.MUSIC_ALL_TITLES_FOLDER.getId(), title

+ "-(" + name + ")", "", album, artist, resource);

musicTrack

.replaceFirstProperty(new UPNP.ALBUM_ART_URI(albumArtUri));

result = musicTrack;

Log.d(getClass().getName(), "MusicTrack: " + id + " Name: " + name

+ " uri: " + uri);

mediaCursor.close();

} else {

Log.d(getClass().getName(), "Item " + myId + " not found.");

}

return result;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值