【问题标题】:How to store the audio/Video file to SQLite database in android.? [duplicate]如何将音频/视频文件存储到android中的SQLite数据库。? [复制]
【发布时间】:2016-04-20 23:23:48
【问题描述】:

我是开发新手,我通过将图像转换为字节数组并将其存储到 BLOB 中的 SQLite 数据库成功地将图像存储到数据库中(找到下面的代码)。但是我没有得到如何将音频/视频存储到数据库中任何人帮助我 PLZ...

 public void getImage(View view){
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("image/* video/*");
    startActivityForResult(Intent.createChooser(intent, "select picture"), 1);

}

public void onActivityResult(int requestCode, int resultCode, Intent data){
    if(resultCode == RESULT_OK){
        Uri imageUri = data.getData();
        String imagePath = getPath(imageUri);

        image1.setVisibility(View.VISIBLE);

        image1.setImageURI(imageUri);
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        Toast.makeText(getApplicationContext(), ""+bitmap, Toast.LENGTH_SHORT).show();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
        img = byteArrayOutputStream.toByteArray();
    }
}

 public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

public void saveImage(View v){

    imageDatabase = new ImageDatabase(this);

    imageDatabase.insert("first",img);

    Toast.makeText(getApplicationContext(), ""+imageDatabase.numberOfRows(),Toast.LENGTH_LONG).show();
}

在上面的代码中,我从 sdcard 中获取图像并在 ImageView 中显示并存储到 DB 中。

【问题讨论】:

    标签: android sqlite android-sqlite sqliteopenhelper android-database


    【解决方案1】:

    将媒体文件存储在内部/外部存储中,并将其路径存储在您的数据库中。

    Saving Files

    【讨论】:

    • 请不要发布链接作为答案。将来链接可能会更改,这将使此答案无用。
    • 你说得对,但我真的不能做得更好。我能做的就是压制这句话
    • Renaud 感谢您的重播,您能帮我发送任何示例代码吗...
    • 音频/视频文件在哪里?你怎么得到它们?使用像您的图像示例这样的选择器?
    • 音频文件位于 sdcard 中,通过选择器或提供音频文件的路径。 (选择器更好)。
    猜你喜欢
    • 2011-01-20
    • 2016-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多