Hi All I am new to Android, I tried accessing Images from Access Folder Android Its works Fine. Below is the Code.
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_picturedetail, container, false);
Bundle b = getArguments();
Drawable d;
am = getActivity().getAssets();
PictDictDetails pd = (PictDictDetails) b.getSerializable("pictobj");
ImageView iv = (ImageView)v.findViewById(R.id.iv_picture);
TextView tv = (TextView)v.findViewById(R.id.tv_picture_name);
String path = pd.getPath();
String name = pd.getName();
try
{
InputStream ims = am.open(path);
d = Drawable.createFromStream(ims, null);
iv.setImageDrawable(d);
}
catch(IOException e)
{
e.printStackTrace();
}
Now I am Trying to Play Video in VideoView with exact Same Logic BUt it is not working
Please Find the below Code, and help me out where i am wrong?
Appreciate your help.
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.videofragment, container, false);
Bundle b = getArguments();
// Drawable d;
am = getActivity().getAssets();
PictDictDetails pd = (PictDictDetails) b.getSerializable("pictobj");
VideoView iv = (VideoView)v.findViewById(R.id.iv_video);
TextView tv = (TextView)v.findViewById(R.id.tv_picture_name);
String path = pd.getPath();
String name = pd.getName();
SurfaceHolder holder = iv.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
MediaPlayer player = new MediaPlayer();
player.setDisplay(holder);
//AssetFileDescriptor afd;
try
{
//InputStream ims = am.open(path);
// d = Drawable.createFromStream(ims, null);
//iv.setImageDrawable(d);
// AssetFileDescriptor descriptor = am.openFd(path);
// long start = descriptor.getStartOffset();
// long end = descriptor.getLength();
/// mediaPlayer.setDataSource(descriptor.getFileDescriptor(),descriptor.getStartOffset(),descriptor.getLength());
// MediaController mediaController= new MediaController();
// mediaController.setAnchorView(iv);
// iv.setMediaController(mediaController);
AssetFileDescriptor afd = am.openFd(path);
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
player.prepareAsync();
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}