在特定视频中打开图库,无需播放

时间:2012-12-20 14:59:19

标签: android video gallery mediarecorder

我有一个可以录制视频的相机应用程序。 (我在三星S3上开发)

我希望能够在最后录制的视频中打开图库。

我使用此代码:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(file.getAbsolutePath()), "video/3gpp");
startActivity(intent);

该代码的问题在于视频会立即启动,以及何时结束 画廊活动关闭。

我希望能够在不播放的情况下打开视频,就像我的三星S3一样。

提前感谢!

1 个答案:

答案 0 :(得分:0)

要打开特定图像,我们可以使用它..它的工作原理。

所以请检查您的要求。希望这会对你有所帮助..

import java.io.File;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



public class SDCARD123Activity extends Activity implements MediaScannerConnectionClient{
    public String[] allFiles;
private String SCAN_PATH ;
private static final String FILE_TYPE="image/*";

private MediaScannerConnection conn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    File folder = new File("/sdcard/Photo/");
    allFiles = folder.list();
 //   uriAllFiles= new Uri[allFiles.length];          
    for(int i=0;i<allFiles.length;i++)
    {
        Log.d("all file path"+i, allFiles[i]+allFiles.length);
    }
  //  Uri uri= Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString()+"/yourfoldername/"+allFiles[0]));


    SCAN_PATH=Environment.getExternalStorageDirectory().toString()+"/Photo/"+allFiles[0];
    System.out.println(" SCAN_PATH  " +SCAN_PATH);

    Log.d("SCAN PATH", "Scan Path " + SCAN_PATH);
    Button scanBtn = (Button)findViewById(R.id.scanBtn);
    scanBtn.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        startScan();
    }});
    }
    private void startScan()
    {
    Log.d("Connected","success"+conn);
    if(conn!=null)
    {
    conn.disconnect();
    }
    conn = new MediaScannerConnection(this,this);
    conn.connect();
    }
@Override
public void onMediaScannerConnected() {
    Log.d("onMediaScannerConnected","success"+conn);
    conn.scanFile(SCAN_PATH, FILE_TYPE);    
}
@Override
public void onScanCompleted(String path, Uri uri) {
    try {
        Log.d("onScanCompleted",uri + "success"+conn);
        System.out.println("URI " + uri);             
        if (uri != null) 
        {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(uri);
        startActivity(intent);
        }
        } finally 
        {
        conn.disconnect();
        conn = null;
        }
       }
}