android:使用SQLite的Blob储存.mp3档案
2010-03-26 10:26
513 查看
25.使用SQLite的Blob储存.mp3档案
这是一个Android范例,兹说明如下:
Step-1: 首先将.mp3档案放入Project的/res/raw/里,如下:
程序一开始执行,建立一个数据库,含有BLOB字段,如下之指令:
sql = "create table mySong("
+ "song_no text not null, "
+ "song_mp3 blob );";
try {
db.execSQL(sql);
} catch (SQLException e) {
Log.e("ERROR", e.toString());
return;
}
Step-2: 从Project的/res/raw/读取*.mp3歌曲,然后分段储存到SQLite的BLOB里,如下之指令:
InputStream is = getResources().openRawResource(rid);
int bufSize = 63*1024;
byte[] buffer = new byte[bufSize];
try {
int size = is.read(buffer);
while(size >= 0){
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
out.write(buffer, 0, size);
out.flush();
out.close();
cv.put("song_mp3", out.toByteArray());
db.insert("mySong", null, cv);
size = is.read(buffer);
}
} catch (IOException e) {
Log.e("ERROR", e.toString());
}
Step-3: 从SQLite的BLOB里,读取歌曲并存入
/data/data/com.misoo.SQ01/files/song.mp3,
如下之指令:
这是一个Android范例,兹说明如下:
Step-1: 首先将.mp3档案放入Project的/res/raw/里,如下:
程序一开始执行,建立一个数据库,含有BLOB字段,如下之指令:
sql = "create table mySong("
+ "song_no text not null, "
+ "song_mp3 blob );";
try {
db.execSQL(sql);
} catch (SQLException e) {
Log.e("ERROR", e.toString());
return;
}
Step-2: 从Project的/res/raw/读取*.mp3歌曲,然后分段储存到SQLite的BLOB里,如下之指令:
InputStream is = getResources().openRawResource(rid);
int bufSize = 63*1024;
byte[] buffer = new byte[bufSize];
try {
int size = is.read(buffer);
while(size >= 0){
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
out.write(buffer, 0, size);
out.flush();
out.close();
cv.put("song_mp3", out.toByteArray());
db.insert("mySong", null, cv);
size = is.read(buffer);
}
} catch (IOException e) {
Log.e("ERROR", e.toString());
}
Step-3: 从SQLite的BLOB里,读取歌曲并存入
/data/data/com.misoo.SQ01/files/song.mp3,
如下之指令:
相关文章推荐
- android:使用SQLite的Blob储存.mp3档案
- Android数据储存之SQLiteDatabase SQLiteOpenHelper类的简单使用
- Android开发 使用Lame把音频文件转换成mp3格式
- Android我的便签-----SQLite的使用方法
- Android SQLite数据库使用示例
- android sqlite 操作使用
- Android Sqlite数据库的使用
- Android中使用SQLiteOpenHelper管理SD卡中的数据库
- Android Sqlite数据库中Sqlite3命令的使用
- Android软件开发之通讯录——添加联系人以及SQLite工具的简单使用
- Android中sqlite基本使用1,(创建数据库,升级,对数据进行增、删、改、查)
- Android数据存储之SQLite使用
- Android进阶篇-Sqlite使用(二)
- Android开发中使用SQLite 数据库
- android 使用sqlite
- Android 开发中使用 SQLite 数据库
- 【Android】13.3 使用SQLite.NET-PCL访问SQLite数据库
- Android开发——SQLite的使用及数据库基础
- 在Android中如何使用SQLite
- Android中使用Sqlite数据库(三) 使用 SQLiteDatabase类实现 增删改查