Click here to Skip to main content
15,936,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
}
});
}
Posted
Comments
alok0000 20-Aug-15 0:35am    
I tried a Lot But I dunno How to work Out, Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900