新聞中心
在現(xiàn)代社會(huì)中,多媒體技術(shù)被廣泛應(yīng)用,并大量地產(chǎn)生了各種各樣的媒體文件,包括音頻、圖片、視頻等。為了更加高效地管理這些多媒體文件,Android系統(tǒng)提供了一個(gè)多媒體數(shù)據(jù)庫(kù)來(lái)幫助開發(fā)人員進(jìn)行數(shù)據(jù)的處理和存儲(chǔ)。該數(shù)據(jù)庫(kù)可以被用于應(yīng)用程序的開發(fā),方便用戶對(duì)自己的多媒體資源進(jìn)行管理和瀏覽。

成都創(chuàng)新互聯(lián)專注于恩施土家企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),商城系統(tǒng)網(wǎng)站開發(fā)。恩施土家網(wǎng)站建設(shè)公司,為恩施土家等地區(qū)提供建站服務(wù)。全流程定制制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
本文將詳細(xì)介紹Android多媒體數(shù)據(jù)庫(kù)的各個(gè)方面,包括數(shù)據(jù)庫(kù)結(jié)構(gòu)、使用方法以及擴(kuò)展等方面。
一、Android多媒體數(shù)據(jù)庫(kù)的結(jié)構(gòu)
Android多媒體數(shù)據(jù)庫(kù)用于存儲(chǔ)和管理多媒體文件的相關(guān)信息,包括音頻、圖片、視頻等。該數(shù)據(jù)庫(kù)主要包含以下表:
1. MediaStore.Images:用于存儲(chǔ)圖片的相關(guān)信息,包括文件名、路徑、大小、日期、拍攝時(shí)間等。該表的主要字段如下:
– _ID:圖片ID
– _DATA:圖片路徑
– DATE_ADDED:添加時(shí)間
– DATE_MODIFIED:修改時(shí)間
– DISPLAY_NAME:顯示名稱
– WIDTH:寬度
– HEIGHT:高度
2. MediaStore.Audio:用于存儲(chǔ)音頻文件的相關(guān)信息,包括文件名、路徑、大小、日期、播放時(shí)間等。該表的主要字段如下:
– _ID:音頻ID
– _DATA:音頻路徑
– DATE_ADDED:添加時(shí)間
– DATE_MODIFIED:修改時(shí)間
– DISPLAY_NAME:顯示名稱
– DURATION:持續(xù)時(shí)間
– ARTIST:藝術(shù)家
– ALBUM:專輯名稱
– TITLE:標(biāo)題
3. MediaStore.Video:用于存儲(chǔ)視頻文件的相關(guān)信息,包括文件名、路徑、大小、日期、播放時(shí)間等。該表的主要字段如下:
– _ID:視頻ID
– _DATA:視頻路徑
– DATE_ADDED:添加時(shí)間
– DATE_MODIFIED:修改時(shí)間
– DISPLAY_NAME:顯示名稱
– DURATION:持續(xù)時(shí)間
– ARTIST:藝術(shù)家
– ALBUM:專輯名稱
– TITLE:標(biāo)題
二、使用Android多媒體數(shù)據(jù)庫(kù)
在Android應(yīng)用程序中,可以通過(guò)Content Provider來(lái)調(diào)用Android多媒體數(shù)據(jù)庫(kù)。其中,Content Provider是Android中的一個(gè)安全機(jī)制,允許應(yīng)用程序與其他應(yīng)用程序共享數(shù)據(jù)。
使用多媒體數(shù)據(jù)庫(kù)需要先獲取Content Resolver對(duì)象,然后通過(guò)Content Resolver對(duì)象對(duì)多媒體庫(kù)中的數(shù)據(jù)進(jìn)行訪問(wèn)。例如,想查詢多媒體庫(kù)中的所有音頻文件,可以使用以下代碼:
“`
ContentResolver resolver = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DATA
};
String sortOrder = MediaStore.Audio.Media.TITLE + ” ASC”;
Cursor cursor = resolver.query(uri, projection, null, null, sortOrder);
if (cursor != null && cursor.moveToFirst()) {
//處理查詢結(jié)果
}
if (cursor != null) {
cursor.close();
}
“`
在上面的代碼中,通過(guò)getContentResolver()方法獲取Content Resolver對(duì)象,MediaStore.Audio.Media.EXTERNAL_CONTENT_URI指定了查詢的URI,projection參數(shù)指定了查詢結(jié)果需要返回的字段,sortOrder參數(shù)指定了排序規(guī)則。查詢得到的結(jié)果存放在游標(biāo)中,可以通過(guò)游標(biāo)進(jìn)行處理。
三、擴(kuò)展Android多媒體庫(kù)
在實(shí)際應(yīng)用中,可能需要擴(kuò)展Android多媒體庫(kù)的功能,以滿足自己的需求。這可以通過(guò)使用Content Provider來(lái)實(shí)現(xiàn)。
需要定義一個(gè)新的Content Provider來(lái)管理擴(kuò)展的數(shù)據(jù)。然后,通過(guò)重載Content Provider的query()方法來(lái)實(shí)現(xiàn)查詢功能。例如,想添加一個(gè)名為“mydata”的表來(lái)存儲(chǔ)自定義數(shù)據(jù),可以使用以下代碼:
“`
public class MyContentProvider extends ContentProvider {
private static final String AUTHORITY = “com.example.myapp.mycontentprovider”;
private static final String BASE_PATH = “mydata”;
public static final Uri CONTENT_URI =
Uri.parse(“content://” + AUTHORITY + “/” + BASE_PATH);
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.query(MySQLiteHelper.TABLE_MYDATA, projection, selection, selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}
…
}
“`
在上述代碼中,重載了query()方法,并通過(guò)SQLiteDatabase對(duì)象查詢自定義數(shù)據(jù),在查詢結(jié)果中設(shè)置了相應(yīng)的通知URI。
然后,在應(yīng)用程序中可以通過(guò)Content Resolver查詢自定義數(shù)據(jù),例如:
“`
Uri uri = MyContentProvider.CONTENT_URI;
String[] projection = {…};
String selection = “…”;
String[] selectionArgs = {…};
String sortOrder = “…”;
Cursor cursor = resolver.query(uri, projection, selection, selectionArgs, sortOrder);
“`
在這里,uri指定了查詢的URI,projection指定了查詢結(jié)果需要返回哪些字段,selection和selectionArgs可以指定查詢的條件,sortOrder指定了排序規(guī)則,查詢結(jié)果使用游標(biāo)進(jìn)行處理。
四、
Android多媒體數(shù)據(jù)庫(kù)是Android系統(tǒng)的一個(gè)重要組成部分,能夠方便地管理各種多媒體文件。使用Android多媒體數(shù)據(jù)庫(kù)需要獲取Content Resolver對(duì)象,并通過(guò)該對(duì)象訪問(wèn)多媒體庫(kù)中的數(shù)據(jù)。如果需要擴(kuò)展Android多媒體庫(kù),可以通過(guò)Content Provider來(lái)實(shí)現(xiàn)。通過(guò)Content Provider可以方便地管理自定義數(shù)據(jù)。Android多媒體數(shù)據(jù)庫(kù)為開發(fā)人員提供了一種方便、快捷的方式來(lái)管理多媒體文件,同時(shí)也為用戶提供了更加優(yōu)秀的多媒體管理功能。
相關(guān)問(wèn)題拓展閱讀:
- android 如何獲取保存的圖片的地址 并存到數(shù)據(jù)庫(kù)中
- 系統(tǒng)運(yùn)行庫(kù)Android主要包含哪些庫(kù)
android 如何獲取保存的圖片的地址 并存到數(shù)據(jù)庫(kù)中
數(shù)據(jù)庫(kù)是什么玩意,瀏覽器可以復(fù)制圖片地址啊,復(fù)制好了隨便你黏貼在哪里
安卓中如何獲取保存的圖片uri 并保存到sqlite數(shù)據(jù)庫(kù)中
有如下兩種方法,僅供參考
方法一:Java代碼
public void saveIcon(Bitmap icon) {
if (icon == null) {
return;
}
// 最終圖標(biāo)要保存到瀏覽器的內(nèi)部數(shù)據(jù)庫(kù)中,系統(tǒng)程序均保存為SQLite格式,Browser也不例外,因?yàn)閳D片是二進(jìn)制的所以使用字節(jié)數(shù)組存儲(chǔ)數(shù)據(jù)庫(kù)的
// BLOB類型
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// 將Bitmap壓縮成PNG編碼,質(zhì)量為100%存儲(chǔ)
icon.compress(Bitmap.CompressFormat.PNG, 100, os);
// 構(gòu)造SQLite的Content對(duì)象,這里也可以使用
raw ContentValues values = new ContentValues();
// 寫入數(shù)據(jù)庫(kù)的
Browser.BookmarkColumns.TOUCH_ICON字段 values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray());
DBUtil.update(….);
//調(diào)用更新或者插入到數(shù)據(jù)庫(kù)的方法
}
}
方法二:如果數(shù)據(jù)表入口時(shí)一個(gè)content:URIJava代碼
import android.provider.MediaStore.Images.Media;
import android.content.ContentValues;
import java.io.OutputStream;
// Save the name and description of an image in a ContentValues map.
ContentValues values = new ContentValues(3);
values.put(Media.DISPLAY_NAME, “road_trip_1”);
values.put(Media.DESCRIPTION, “Day 1, trip to Los Angeles”);
values.put(Media.MIME_TYPE, “image/jpeg”);
// Add a new record without the bitmap, but with the values just set.
// insert() returns the URI of the new record.
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
// Now get a handle to the file for that record, and save the data into it.
// Here, sourceBitmap is a Bitmap object representing the file to save to the database.
try {
OutputStream outStream = getContentResolver().openOutputStream(uri);
sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
outStream.close();
} catch (Exception e) {
Log.e(TAG, “exception while writing image”, e);
}
原文請(qǐng)看
用這兩個(gè)方法應(yīng)該可以滿足你的要求。
方法一:Java代碼 public void saveIcon(Bitmap icon) { if (icon == null) { return; } // 最終圖標(biāo)要保存到瀏覽器的內(nèi)部數(shù)據(jù)庫(kù)中,系統(tǒng)程序均保存為SQLite格式,Browser也不例外,因?yàn)閳D片是二進(jìn)制的所以使用字節(jié)數(shù)組存儲(chǔ)數(shù)據(jù)庫(kù)的 // BLOB類型 final ByteArrayOutputStream os = new ByteArrayOutputStream(); // 將Bitmap壓縮成PNG編碼,質(zhì)量為100%存儲(chǔ) icon.compress(Bitmap.CompressFormat.PNG, 100, os); // 構(gòu)造SQLite的Content對(duì)象,這里也可以使用raw ContentValues values = new ContentValues(); // 寫入數(shù)據(jù)庫(kù)的Browser.BookmarkColumns.TOUCH_ICON字段 values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray()); DBUtil.update(….);//調(diào)用更新或者插入到數(shù)據(jù)庫(kù)的方法 } 方法二:如果數(shù)據(jù)表入口時(shí)一個(gè)content:URIJava代碼 import android.provider.MediaStore.Images.Media; import android.content.ContentValues; import java.io.OutputStream; // Save the name and description of an image in a ContentValues map. ContentValues values = new ContentValues(3); values.put(Media.DISPLAY_NAME, “road_trip_1”); values.put(Media.DESCRIPTION, “Day 1, trip to Los Angeles”); values.put(Media.MIME_TYPE, “image/jpeg”); // Add a new record without the bitmap, but with the values just set. // insert() returns the URI of the new record. Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values); // Now get a handle to the file for that record, and save the data into it. // Here, sourceBitmap is a Bitmap object representing the file to save to the database. try { OutputStream outStream = getContentResolver().openOutputStream(uri); sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream); outStream.close(); } catch (Exception e) { Log.e(TAG, “exception while writing image”, e); }
系統(tǒng)運(yùn)行庫(kù)Android主要包含哪些庫(kù)
* Bionic系統(tǒng) C 庫(kù):C語(yǔ)言標(biāo)準(zhǔn)庫(kù),系統(tǒng)更底層的庫(kù),C庫(kù)通過(guò)Linux系統(tǒng)來(lái)調(diào)用。
* 多媒體庫(kù)(MediaFramework):Android系統(tǒng)多媒體庫(kù),基于 PacketVideo OpenCORE,該庫(kù)支持多種常見格式的音頻、視頻的回放和錄制,以及圖片,比如MPEG4、MP3、AAC、AMR、JPG、PNG等。
* SGL:2D圖形引擎庫(kù)。
* SSL:位于TCP/
IP協(xié)議
與各種應(yīng)用層協(xié)議之間,為數(shù)據(jù)通信提供支持。
* OpenGL ES 1.0:3D效果的支持。
* SQLite:
關(guān)系數(shù)據(jù)庫(kù)
。
* Webkit:Web瀏覽器引擎。
* FreeType:位圖(bitmap)及矢量(vector)。
android media數(shù)據(jù)庫(kù)的介紹就聊到這里吧,感謝你花時(shí)間閱讀本站內(nèi)容,更多關(guān)于android media數(shù)據(jù)庫(kù),Android多媒體數(shù)據(jù)庫(kù)詳解,android 如何獲取保存的圖片的地址 并存到數(shù)據(jù)庫(kù)中,系統(tǒng)運(yùn)行庫(kù)Android主要包含哪些庫(kù)的信息別忘了在本站進(jìn)行查找喔。
成都網(wǎng)站營(yíng)銷推廣找創(chuàng)新互聯(lián),全國(guó)分站站群網(wǎng)站搭建更好做SEO營(yíng)銷。
創(chuàng)新互聯(lián)(www.cdcxhl.com)四川成都IDC基礎(chǔ)服務(wù)商,價(jià)格厚道。提供成都服務(wù)器托管租用、綿陽(yáng)服務(wù)器租用托管、重慶服務(wù)器托管租用、貴陽(yáng)服務(wù)器機(jī)房服務(wù)器托管租用。
網(wǎng)站標(biāo)題:Android多媒體數(shù)據(jù)庫(kù)詳解 (android media數(shù)據(jù)庫(kù))
瀏覽地址:http://m.5511xx.com/article/codpgps.html


咨詢
建站咨詢
