Such a problem, I try to play video files from a folder, by clicking on the video file, the video player starts up, and then an error is written: the video is not supported. The video is correct and error-free, recorded from the camera of the same smartphone (files are played, entered through total in the folder from which I am trying to play and the video was played by a standard player)

method for finding files with the extension mp4:

public ArrayList<String> getVideoFiles(String directoryPath) { ArrayList<String> result = new ArrayList<>(); File directory = new File(directoryPath); File files[] = directory.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".MP4"); } }); for (File file : files) { result.add(file.getAbsoluteFile().toString()); } return result; } 

I call the method here:

  @Override public void onBindViewHolder(VideoPreviewHolder holder, int position) { holder.mVideoPreviewImageView.setImageBitmap(mItems.get(position).getVideoBitmap()); holder.mVideoPreviewTextView.setText(mItems.get(position).getVideoName()); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreviewActivity previewActivity = new PreviewActivity(); ArrayList<String> files = previewActivity .getVideoFiles(Environment.getExternalStorageDirectory() + "/.OtherFile"); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse( String.valueOf(files))); intent.setDataAndType(Uri.parse(String.valueOf(Environment.getExternalStorageDirectory() + "/.OtherFile")), "video/MP4"); v.getContext().startActivity(intent); } }); } 

Combinations with: "video / mp4" / "video / MP4" and return name.endsWith (". MP4"); / return name.endsWith (". Mp4"); don't solve problems.

UPDATE:

  public class VideoPreviewAdapter extends RecyclerView.Adapter<VideoPreviewAdapter.VideoPreviewHolder> { private Context mContext; private ArrayList<VideoPreview> mItems; private List<String> path_vid; public VideoPreviewAdapter(Context context) { mContext = context; mItems = new ArrayList<>(); } public void addItems(ArrayList<VideoPreview> items) { mItems.addAll(items); notifyDataSetChanged(); } public void clearItems() { mItems.clear(); } @Override public VideoPreviewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater layoutInflater = LayoutInflater.from(mContext); View view = layoutInflater.inflate(R.layout.video_preview_item, parent, false); return new VideoPreviewHolder(view); } /* public void searchVid(File dir) { String pattern = ".MP4"; //Get the listfile of that flder final File listFile[] = dir.listFiles(); if (listFile != null) { for (int i = 0; i < listFile.length; i++) { final int x = i; if (listFile[i].isDirectory()) { walkdir(listFile[i]); } else { if (listFile[i].getName().endsWith(pattern)) { // Do what ever u want, add the path of the video to the list path_vid.add(listFile[i]); } } } } }*/ @Override public void onBindViewHolder(VideoPreviewHolder holder, int position) { holder.mVideoPreviewImageView.setImageBitmap(mItems.get(position).getVideoBitmap()); holder.mVideoPreviewTextView.setText(mItems.get(position).getVideoName()); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* PreviewActivity previewActivity = new PreviewActivity(); ArrayList<String> files = previewActivity .getVideoFiles(Environment.getExternalStorageDirectory() + "/.OtherFile"); for (String fileArray : files) { }*/ String path = Environment.getExternalStorageDirectory() + "/.OtherFile"; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(path))); intent.setDataAndType(Uri.parse( String.valueOf(Environment.getExternalStorageDirectory() + "/.OtherFile")), "video/MP4"); v.getContext().startActivity(intent); } }); } @Override public int getItemCount() { return mItems.size(); } public class VideoPreviewHolder extends RecyclerView.ViewHolder { public ImageView mVideoPreviewImageView; public TextView mVideoPreviewTextView; public VideoPreviewHolder(View itemView) { super(itemView); mVideoPreviewImageView = (ImageView) itemView.findViewById(R.id.video_preview_image_view); mVideoPreviewTextView = (TextView) itemView.findViewById(R.id.video_preview_text_view); } } } 
  • As far as I understand, you never designate a specific file that you want to play. What result do you expect from a code that has only a path to a folder or a list of paths to several files ? - post_zeew
  • @ post_zeew I understand you, then I need to get the file, and then transfer to setDataAndType? and to get the file, I’ll to the handler holder.itemView.setOnClickListener how should I transfer the video file from the folder? - upward
  • one
    Well, yes, something like that. You have an array of data in the adapter, and you have a position in the onBindViewHolder(...) method. With the help of position you can get a specific object and a very specific path to the selected video file from your data set. - post_zeew pm
  • one
    Oh ... To add elements to the list in the adapter, the addItems(...) method is used, that is, after adding elements, these elements will be in mItems . Each element contains, in particular, the path to a specific video file . In the onBindViewHolder(...) method, you can get the selected item by calling the get(position) mItems object. And then from this element you can get the path to the file using the corresponding getter. - post_zeew
  • one
    My advice to you: leave while you are your application. Create a simple application in which the user can add the entered words to the list. After that, implement the output of the notification with the text of the clicked list item. How to deal with this - go back to your application. Many points will become clear. - post_zeew

1 answer 1

Understood himself, maybe someone will need.

 String strin = mItems.get(position).getVideoName(); File path_file = new File(Environment.getExternalStorageDirectory() + "/.OtherFile/" + strin); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.valueOf(path_file))); intent.setDataAndType(Uri.parse(String.valueOf(path_file)), "video/mp4") ; v.getContext().startActivity(intent);