I am playing a encrypted mp4 video file from sdcard. for this what i do .....

**STEP 1.** i copy file from sdcard in internal memory and i write that file in world readable and world writeable format so that that i could Play

**STEP 2.** I decrypt that file in a temprary folder

**STEP 3.** now i play this , file plays no problem

Problem is this process takes time , because file is large about 25 mb , and this process ( copying and decryption ) takes about 2 minutes time

after some reading i found a solution of this problem i could reduce time by using 
libmedia library , but i am facing some problem 
 when i play this by using libmedia library 
error comes in log cat

```
10-10 06:33:42.908: E/MediaPlayer(9249): error (1, -2147483648)

```

on Activity screen i got a message in dialog 
"can't play video"

libmedia library link is <http://libeasy.alwaysdata.net/>

thanks for your valuable suggestion and help

my activity code is 

```
package com.example.playvideo2;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;

import fr.maxcom.http.LocalSingleHttpServer;
import fr.maxcom.libmedia.Licensing;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity implements OnCompletionListener 
{
    LocalSingleHttpServer mServer;
    VideoView mVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video_view);

        Licensing.allow(this);
        playENCVideo(Environment.getExternalStorageDirectory()
                + "/encVideo.mp4");
    }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public void playENCVideo(String path) {

    try {
        Cipher decipher = null;

        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecretKey skey = kgen.generateKey();

        decipher = Cipher.getInstance("AES");

        decipher.init(Cipher.DECRYPT_MODE, skey);

        mServer = new LocalSingleHttpServer();

        mServer.setCipher(decipher);
        mServer.start();

        path = mServer.getURL(path);

        mVideoView = (VideoView) findViewById(R.id.videoView1);
        mVideoView.setVideoPath(path);

        // mVideoView.setMediaController(new MediaController(this));
        // mVideoView.requestFocus();
        mVideoView.start();
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public void onCompletion(MediaPlayer mp) {
    // MediaPlayer.OnCompletionListener interface
    mServer.stop();

}

}

```

my manifest file is 

```
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.playvideo2"
    android:versionCode="1"
    android:versionName="1.0" 
    >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.playvideo2.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <meta-data
        android:name="fr.maxcom.libmedia.apiKey"
        android:value="qV1T3Zf+IyCpb1jomsomS3NUXBk7LdDaV31DcwmVIoMpvWWK8xAQIl1RUVWQegSt2jJbwH+cleik7YCH2/chP1JWdhpSfgMaNRl3fDMOez8mGn98Jhp7KyAffjc5RA==" />
</application>

</manifest>

```

This is that code which i used for encryption and decryption

```
        FileInputStream fis = new FileInputStream(new File("D:/QLurnVideo/inputVideo.mp4"));
        File outfile = new File("D:/QLurnVideo/encVideo.mp4");
        int read;
        if(!outfile.exists())
            outfile.createNewFile();
        File decfile = new File("D:/QLurnVideo/decVideo.mp4");
        if(!decfile.exists())
            decfile.createNewFile();
        FileOutputStream fos = new FileOutputStream(outfile);
        FileInputStream encfis = new FileInputStream(outfile);
        FileOutputStream decfos = new FileOutputStream(decfile);
        Cipher encipher = Cipher.getInstance("AES");
        Cipher decipher = Cipher.getInstance("AES");
        KeyGenerator kgen = KeyGenerator.getInstance("AES");

        SecretKey skey = kgen.generateKey();
        //Lgo
        encipher.init(Cipher.ENCRYPT_MODE, skey);
        CipherInputStream cis = new CipherInputStream(fis, encipher);
        decipher.init(Cipher.DECRYPT_MODE, skey);
        CipherOutputStream cos = new CipherOutputStream(decfos,decipher);
        while((read = cis.read())!=-1)
                {
                    fos.write((char)read);
                    fos.flush();
                }   
        fos.close();
        while((read=encfis.read())!=-1)
        {
            cos.write(read);
            cos.flush();
        }
cos.close();

```