绝地救生配置开始游戏时弹出的窗口,求解

2442人阅读
Android(128)
http://www.android1.net/Topic.aspx?BoardID=11&TopicID=588
講義摘錄之25: 使用SQLite的Blob儲存*.mp3檔案
這是一個Android範例,茲說明如下:
Step-1: 首先將.mp3檔案放入Project的/res/raw/裡,如下:
程式一開始執行,建立一個資料庫,含有BLOB欄位,如下之指令:
sql = "create table mySong("
+ "song_no text not null, "
+ "song_mp3 blob );";
db.execSQL(sql);
} catch (SQLException e) {
Log.e("ERROR", e.toString());
Step-2: 從Project的/res/raw/讀取*.mp3歌曲,然後分段儲存到SQLite的BLOB裡,如下之指令:
InputStream is = getResources().openRawResource(rid);
int bufSize = 63*1024;
byte[] buffer
= new byte[bufSize];
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,
如下之指令:
FileOutputStream os =
os = openFileOutput("song.mp3", MODE_WORLD_READABLE);
} catch(FileNotFoundException e){
Log.e("ERROR", e.toString());
byte[] red_
//----------------------------------------
mOpenHelper = new DatabaseHelper(this);
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
String col[] = {"song_no", "song_mp3" };
cur = db.query("mySong", col, cond, null, null, null, null);
cur.moveToFirst();
while(!cur.isAfterLast()){
red_buf = cur.getBlob(1);
os.write(red_buf);
cur.moveToNext();
os.flush();
os.close();
}catch(Exception e){
Log.e("ERROR", e.toString());
Step-4: 使用MediaPlayer將
/data/data/com.misoo.SQ01/files/song.mp3,
播放出來,如下之指令:
String path = "/data/data/com.misoo.SQ01/files/song.mp3";
mPlayer = new MediaPlayer();
mPlayer.setDataSource(path);
mPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
mPlayer.start();
其實,BLOB欄位可儲存很大的資料量,在本範例裡,刻意將歌曲切成許多段,逐一存入資料庫裏。其目的只是為了舉例而已。
package com.misoo.SQ01;
import java.io.ByteArrayOutputS
import java.io.FileNotFoundE
import java.io.FileOutputS
import java.io.IOE
import java.io.InputS
import android.app.A
import android.content.ContentV
import android.content.C
import android.database.C
import android.database.SQLE
import android.database.sqlite.SQLiteD
import android.database.sqlite.SQLiteOpenH
import android.media.MediaP
import android.os.B
import android.util.L
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.LinearL
public class ac01 extends Activity implements OnClickListener{
private static final String DB_NAME = "mp3Song.db";
private static final int DB_VERSION = 2;
private Button btn, btn2, btn3;
private MediaPlayer mP
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
public void onCreate(SQLiteDatabase db) {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
btn = new Button(this);
btn.setId(101);
btn.setText("play");
btn.setBackgroundResource(R.drawable.heart);
btn.setOnClickListener(this);
LinearLayout.LayoutParams param
= new LinearLayout.LayoutParams(80, 50);
param.topMargin = 10;
layout.addView(btn, param);
btn2 = new Button(this);
btn2.setId(102);
btn2.setText("stop");
btn2.setBackgroundResource(R.drawable.heart);
btn2.setOnClickListener(this);
layout.addView(btn2, param);
btn3 = new Button(this);
btn3.setId(103);
btn3.setText("exit");
btn3.setBackgroundResource(R.drawable.heart);
btn3.setOnClickListener(this);
layout.addView(btn3, param);
setContentView(layout);
setTitle("Saving into SQliteDB...");
//---------------------------------
setTitle("Saved in SQliteDB.");
private DatabaseHelper mOpenH
public void init(){
mOpenHelper = new DatabaseHelper(this);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
//-----------------------------------
String sql = "drop table mySong";
db.execSQL(sql);
} catch (SQLException e) {
Log.e("ERROR", e.toString());
//-----------------------------------
sql = "create table mySong("
+ "song_no text not null, "
+ "song_mp3 blob );";
db.execSQL(sql);
} catch (SQLException e) {
Log.e("ERROR", e.toString());
//---------------------------------
SaveOneSong(db,"s01", R.raw.den_li_guing);
public void SaveOneSong(SQLiteDatabase db, String key, int rid){
ContentValues cv = new ContentValues();
cv.put("song_no", key);
InputStream is = getResources().openRawResource(rid);
int bufSize = 63*1024;
byte[] buffer
= new byte[bufSize];
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());
public void play(String cond){
FileOutputStream os =
os = openFileOutput("song.mp3", MODE_WORLD_READABLE);
} catch(FileNotFoundException e){
Log.e("ERROR", e.toString());
byte[] red_
//----------------------------------------
mOpenHelper = new DatabaseHelper(this);
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
String col[] = {"song_no", "song_mp3" };
cur = db.query("mySong", col, cond, null, null, null, null);
cur.moveToFirst();
while(!cur.isAfterLast()){
red_buf = cur.getBlob(1);
os.write(red_buf);
cur.moveToNext();
os.flush();
os.close();
}catch(Exception e){
Log.e("ERROR", e.toString());
String path = "/data/data/com.misoo.SQ01/files/song.mp3";
mPlayer = new MediaPlayer();
mPlayer.setDataSource(path);
mPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
mPlayer.start();
public void onClick(View v) {
switch (v.getId()) {
String cond = "song_no='s01'";
play(cond);
public void stop() {
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:369958次
积分:4228
积分:4228
排名:第5809名
原创:28篇
转载:133篇
评论:94条
(2)(1)(1)(1)(1)(1)(2)(1)(1)(2)(1)(1)(7)(8)(5)(14)(23)(54)(27)(8)3716人阅读
sqlite3使用(10)
一、初识sqlite
&&&&&&&&&偶然的机会接触到sqlite,不禁惊叹sqlite的体型小巧而功能强大(看来软件也不可貌相哦),Sqlite 是开源的内存数据库(也可以称之为内嵌式数据库),大量无私的程序员为sqlite发展贡献了自己的力量。Sqlite 应用极广,手机、mp3,机顶盒可能存在sqlite身影,Apple的Mac os,linux,或者windows在安装第三方软件时也可以应用sqlite。
&&&&&&&&&Sqlite技术优点:
1.&&Sqlite轻量级、跨平台的关系型开源内存数据库,使用sqlite只需带上动态库,就可使用sqlite全部功能(动态库Windows下487KB,Linux下347KB);
2.&&&核心引擎不依赖第三方软件,也不需要安装;
3.&&&数据库中所有的信息(比如表、视图、触发器、等)都包含在一个文件内。这个文件可以copy到其它目录或其它机器上,也照用不误。如果使用内存方式,可以没有该文件;
4.&&&除了主流操作系统,SQLite还支持了很多冷门的操作系统。它对很多嵌入式系统(比如Android、Windows Mobile、Symbin、Palm、VxWorks等)也支持;
5.&&&SQLite的API不区分当前操作的数据库是在内存还是在文件(对于存储介质是透明的);
&&&&&&&& 缺点:
1.&&& 并发访问的锁机制
SQLite在并发(包括多进程和多线程)读写方面的性能不太理想。数据库可能会被写操作独占,从而导致其它读写操作阻塞或出错;
2.&&&& SQL标准支持不全
如不支持外键约束;
&&&&&&&&&&看来还是优点多于缺点!呵呵!
二、sqlite体系机构
&&&&&&&&&&&&&& sqlite模块将 查询过程分为几个不连续的任务,在结构栈的顶部编译查询语句,中不执行,在底部处理操作系统的存储和接口。
&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&图1-2SQLite的体系结构
(注:结构图转载于《SQLite权威指南》)
三、sqlite文件数据库、内存数据库建立及导入导出
&&&&&&&&&& sqlite官网()同时提供已编译版本和源程序。同时适用于Windows和linux。
&&&&&&&&&& 经过前面sqlite热身之后,赶紧转入正题,干点正事!(*^__^*)
3.1 文件数据库、内存数据库的建立
3.1.1文件数据库的建立
1)& 下载sqlite最新版本sqlite3.exe;
2)& dos进入到执行程序目录下;
3)& 输入 sqlite3& d:\test.db(如果后面执行路径存在test.db 则打开数据库;如果执行路径下不存在test.db则新建test.db);
1)& 下载sqlite最新版本sqlite3;
2)& Shell进入到可知性程序目录下;
3) 输入sqlite3& /home/test.db(如果后面执行路径存在test.db 则打开数据库;如果执行路径下不存在test.db则新建test.db);
至此则打开或者新建一个文件数据库库;
3.1.2 内存数据库的建立
&调用实例:
3.3 文件数据库命令格式的导入导出
&&&&&&&& 3.3.1 文件数据库命令格式数据导出、备份
方法一:(sqlite数据库内部)
Sqlite&.output d:\test.sql
Sqlite&.dump
Sqlite&.output stdout
方法二:(dos命令行)
sqlite3 525.db .dump&haha.sql
3.3.2文件数据库命令格式数据导入
sqlite&.read& file.sql
&&&&&&&&&&&& 今天暂且到这了,to be continue……
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:392510次
积分:4600
积分:4600
排名:第5081名
原创:79篇
转载:129篇
评论:13条
(3)(2)(4)(2)(1)(2)(1)(1)(5)(3)(1)(3)(7)(6)(2)(3)(4)(2)(3)(5)(2)(3)(1)(14)(16)(14)(13)(17)(7)(11)(27)(8)(17)(1)(1)如何在SQLite数据库中存取图片文件 - 其它数据库 - 编程入门网
如何在SQLite数据库中存取图片文件
前段时间在做一款嵌入式项目,用到了SQLite数据库,现在就SQLite数据库中存取图片问题来与大家共享一下,对于二进制数据我们自然是不能够直接进行存储,在SQLite中我们可以将其转换而后存储。
下面就言归正传
在对主句操作之前我们先要打开数据库,SQLite给用户提供了丰富的API,足以使我们来驾驭它,利用sqlite3_open()函数,打开我们所要操作的数据库,接下来就是对于我们的图片文件的操作了,我在这里的方法便是将图片文件转换成字符流,而后进行存储。
下面我就以一个简单的范例来说明问题吧.....
#include &stdio.h&
#include &sqlite3.h&
#include &stdlib.h&
static sqlite3 *db=NULL;
static sqlite3_stmt *stmt=NULL;
long filesize=0;
int main(int argc, char *argv[])
int rc,i,j;
sqlite3_open(&dishes.db&, &db);
sqlite3_prepare(db, &update dishes_table set dish_image=?where dish_name='x';&, -1, &stmt, 0);
fp=fopen(&x.jpg&,&rb&);
if(fp != NULL)
fseek(fp, 0, SEEK_END);
filesize = ftell(fp);
fseek(fp, 0, SEEK_SET);
ffile = (char *)malloc(filesize + 1);
size_t sz = fread(ffile, sizeof(char), filesize+1, fp);
fclose(fp);
sqlite3_bind_blob(stmt, 1, ffile, filesize, NULL);
rc=sqlite3_step(stmt);
free(ffile);
sqlite3_finalize(stmt);
sqlite3_close(db);

我要回帖

更多关于 绝地救生加速 的文章

 

随机推荐