视频的路径已设置并通过领域,但视频不会显示在Listview中

时间:2017-10-27 05:36:24

标签: android android-videoview

我的活动

public class CommonChattingAttachmentActivity extends BaseActivity {

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

        lv= (ListView) findViewById(R.id.Listview_common);
        commonchat = findViewById(R.id.commonchat);
        functions = findViewById(R.id.functions);
        //times=(TextView) findViewById(R.id.times);

        imglocation=(ImageView) findViewById(R.id.imglocation);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

                CommonChat items = (CommonChat) lv.getItemAtPosition(position);
                view.setBackgroundColor(Color.parseColor("#e5e5e5"));
                change2();

            }
        });
        lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long l) {
                CommonChat item = (CommonChat) lv.getItemAtPosition(position);
                view.setBackgroundColor(Color.parseColor("#a9a9a9"));
                change1();
                h=item.getDescription();
                onclick();
               // onitemclick();
                return true;

            }
        });

         imgcopy = (ImageView) functions.findViewById(R.id.imagecopy);
         imgdelete=(ImageView) functions.findViewById(R.id.imgdelete);


        //INITIALIZE REALM
        realm=Realm.getDefaultInstance();
        setAdapter();
        displayInputDialog();
       //    timed();
        imgcam=(ImageView)findViewById(R.id.imgcam);
        imgallery=(ImageView) findViewById(R.id.imggallery);
        imgattach=(ImageView) findViewById(R.id.imgattach);
        imgallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                galleryIntent();
            }
        });
        imgcam.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cameraIntent();
            }
        });
        imgattach.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectImage();
            }
        });
        imglocation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


  Intent i = new Intent(CommonChattingAttachmentActivity.this, MapsActivity.class);
                    startActivityForResult(i, 1);
            }
        });



    }

public void onclick()
{
    imgcopy.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            ClipboardManager cm = (ClipboardManager) getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
            cm.setText(h);
        }
    });
    imgdelete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String type = h;
            final RealmResults<CommonChat> students = realm.where(CommonChat.class).findAll();

            CommonChat CommonChat = students.where().equalTo("description", type).findFirst();

            if (CommonChat != null) {

                if (!realm.isInTransaction()) {
                    realm.beginTransaction();
                }

                CommonChat.removeFromRealm();

                realm.commitTransaction();
            }
        }
            //final int position2 = holder.getAdapterPosition();



    });

}
    public void setAdapter()
    {
        lv= (ListView) findViewById(R.id.Listview_common);
        final CommonChatRealmHelper helper=new CommonChatRealmHelper(realm);
        helper.retrieveFromDB();
        CCAA adapter=new CCAA(CommonChattingAttachmentActivity.this,helper.justRefresh());
        lv.setAdapter(adapter);
        adapter.notifyDataSetChanged();
        realmChangeListener=new RealmChangeListener() {
            @Override
            public void onChange() {
                CCAA adapter=new CCAA(CommonChattingAttachmentActivity.this,helper.justRefresh());
                lv.setAdapter(adapter);
                adapter.notifyDataSetChanged();
            }
        };
        realm.addChangeListener(realmChangeListener);
    }

    //DISPLAY INPUT DIALOG
    public void displayInputDialog()
    {

        //EDITTEXTS
        descEditTxt= (EditText) findViewById(R.id.editwrite);
        ImageView fab = (ImageView) findViewById(R.id.send);

        //SAVE
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String desc = descEditTxt.getText().toString();
                CommonChat s = new CommonChat();
                s.setDescription(desc);
                CommonChatRealmHelper helper = new CommonChatRealmHelper(realm);
                if (helper.save(s)) {
                    descEditTxt.setText("");
                    setAdapter();
                   // addImages();
                }
                else {
                    Toast.makeText(CommonChattingAttachmentActivity.this, "Invalid Data", Toast.LENGTH_SHORT).show();
                }
            }




        });
    }

    public void cameraIntent() {
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, REQUEST_CAMERA);
        //intent.putExtra("camera",REQUEST_CAMERA);

    }
    public void galleryIntent() {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);//
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
    }
    public void SaveMapData(String result1,String result2) {
        try {
            Realm realm = Realm.getDefaultInstance();
            realm.beginTransaction();
            CommonChat s = realm.createObject(CommonChat.class);
            s.setLatitude(result1);
            s.setLongitude(result2);
            realm.commitTransaction();
            realm.close();
            CommonChatRealmHelper helper = new CommonChatRealmHelper(realm);
            if (helper.save(s)) {
                setAdapter();
            }
            else
            {
                Toast.makeText(CommonChattingAttachmentActivity.this, "Invalid Data", Toast.LENGTH_SHORT).show();
            }
           // Log.d("path", result);
            Log.d("working realm", "yes....");
            Toast.makeText(getApplicationContext(),"Set Image URL"+result,Toast.LENGTH_LONG).show();
        }
        catch (Exception ex){
            Toast.makeText(getApplicationContext(),"Nope its not done",Toast.LENGTH_LONG).show();
        }
    }
    public void selectImage() {
        final CharSequence[] items = { "Take Photo", "Choose from Library","Camera Video","Gallery Video","Current Location",
                "Cancel" };
        AlertDialog.Builder builder = new AlertDialog.Builder(CommonChattingAttachmentActivity.this);
        builder.setTitle("Add Photo!");
        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int item) {
                boolean result=Utility.checkPermission(CommonChattingAttachmentActivity.this);
                if (items[item].equals("Take Photo")) {
                    userChoosenTask="Take Photo";
                    if(result)
                        cameraIntent();
                } else if (items[item].equals("Choose from Library")) {
                    userChoosenTask="Choose from Library";
                    if(result)
                        galleryIntent();
                }
                else if (items[item].equals("Camera Video")) {
                    userChoosenTask="Camera Video";
                    if(result)
                        startRecording();
                }
                else if (items[item].equals("Gallery Video")) {
                    userChoosenTask="Gallery Video";
                    if(result)
                        CaptureVideoFromGallery();
                }
                else if (items[item].equals("Current Location")) {
                    userChoosenTask="Current Location";
                    if(result)
                      mapactivity();
                }

                    else if (items[item].equals("Cancel")) {
                    dialog.dismiss();
                }
            }
        });
        builder.show();
    }
public void mapactivity()
{




 Intent i=new Intent(CommonChattingAttachmentActivity.this,MapsActivity.class);
    startActivity(i);
}
    public void startRecording()
    {
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

        // create a file to save the video
        fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);

        // set the image file name
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

        // set the video image quality to high
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

        // start the Video Capture Intent
        startActivityForResult(intent, VIDEO_CAPTURE);

    }
    /** Create a file Uri for saving an image or video */
    private static Uri getOutputMediaFileUri(int type){

        return Uri.fromFile(getOutputMediaFile(type));
    }

    /** Create a File for saving an image or video */
    private static File getOutputMediaFile(int type){

        // Check that the <a href="#">SDCard</a> is mounted
        File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), "MyCameraVideo");


        // Create the storage directory(MyCameraVideo) if it does not exist
        if (! mediaStorageDir.exists()){

            if (! mediaStorageDir.mkdirs()){

               // output.setText("Failed to create directory MyCameraVideo.");

               // Toast.makeText(this, "Failed to create directory MyCameraVideo.", Toast.LENGTH_LONG).show();

                Log.d("MyCameraVideo", "Failed to create directory MyCameraVideo.");
                return null;
            }
        }



        java.util.Date date= new java.util.Date();
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                .format(date.getTime());

        File mediaFile;

        if(type == MEDIA_TYPE_VIDEO) {

            // For unique video file name appending current timeStamp with file name
            mediaFile = new File(mediaStorageDir.getPath() + File.separator +
                    "VID_"+ timeStamp + ".mp4");

        } else {
            return null;
        }

        return mediaFile;
    }

    public void CaptureVideoFromGallery()
    {
        Intent intent = new Intent();
        intent.setType("video/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Video"), SELECT_FILES);
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case Utility.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    if(userChoosenTask.equals("Take Photo"))
                        cameraIntent();
                    else if(userChoosenTask.equals("Choose from Library"))
                        galleryIntent();
                } else {
                }
                break;
        }
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_FILE) {
                onSelectFromGalleryResult(data);
            }
            else if (requestCode == REQUEST_CAMERA) {
                onCaptureImageResult(data);
            }
           else if (requestCode == SELECT_FILES) {
                onSelectFromGalleryVideoResults(data);
            }
            else if(requestCode==1)
            {
                if(resultCode == Activity.RESULT_OK){
                    String result1=data.getStringExtra("lat");
                    String result2=data.getStringExtra("lng");

                        SaveMapData(result1,result2);


                }

            }
            else if (requestCode == VIDEO_CAPTURE) {

                    Toast.makeText(this, "Video has been saved to:\n" + data.getData(), Toast.LENGTH_LONG).show();
                    SaveVideoData(String.valueOf(data.getData()));
                } else if (resultCode == RESULT_CANCELED) {
                    Toast.makeText(this, "Video recording cancelled.", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(this, "Failed to record video", Toast.LENGTH_LONG).show();
                }
        }
    }
    @SuppressWarnings("deprecation")
    public void onSelectFromGalleryResult(Intent data) {

        Toast.makeText(CommonChattingAttachmentActivity.this,"My bm"+data,Toast.LENGTH_LONG).show();
        SaveImageVideoData(String.valueOf(data.getData()),"gallery");

    }
    @SuppressWarnings("deprecation")
    public void onSelectFromGalleryVideoResults(Intent data) {

        Toast.makeText(CommonChattingAttachmentActivity.this,"My bm"+data,Toast.LENGTH_LONG).show();
        SaveVideoData(String.valueOf(data));

    }

    public void  onCaptureImageResult(Intent data) {
        Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        thumbnail.compress(Bitmap.CompressFormat.PNG, 90, bytes);
        File destination = new File(Environment.getExternalStorageDirectory(),
                System.currentTimeMillis() + ".png");
        FileOutputStream fo;
        try {
            destination.createNewFile();
            fo = new FileOutputStream(destination);
            fo.write(bytes.toByteArray());
            fo.close();
            Toast.makeText(CommonChattingAttachmentActivity.this,"No Error",Toast.LENGTH_LONG).show();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(CommonChattingAttachmentActivity.this,"Error Arrived",Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(CommonChattingAttachmentActivity.this,"Error Arrived again",Toast.LENGTH_LONG).show();
        }
        SaveImageVideoData(String.valueOf(destination),"camera");
        Toast.makeText(CommonChattingAttachmentActivity.this,"its done",Toast.LENGTH_LONG).show();


    }

    public void SaveImageVideoData(String data,String flag) {
        try {
            Realm realm = Realm.getDefaultInstance();
            realm.beginTransaction();
            CommonChat s = realm.createObject(CommonChat.class);
            s.setImageUrl(data);
           // s.setVideoUrl(data);
            s.setFlag(flag);
            realm.commitTransaction();
            realm.close();
            CommonChatRealmHelper helper = new CommonChatRealmHelper(realm);
            if (helper.save(s)) {
                setAdapter();
            }
            else
            {
                Toast.makeText(CommonChattingAttachmentActivity.this, "Invalid Data", Toast.LENGTH_SHORT).show();
            }
            Log.d("path", data);
            Log.d("working realm", "yes....");
            Toast.makeText(getApplicationContext(),"Set Image URL"+data,Toast.LENGTH_LONG).show();
        }
        catch (Exception ex){
            Toast.makeText(getApplicationContext(),"Nope its not done",Toast.LENGTH_LONG).show();
        }
    }
    public void SaveVideoData(String data) {
        try {
            Realm realm = Realm.getDefaultInstance();
            realm.beginTransaction();
            CommonChat s = realm.createObject(CommonChat.class);
           // s.setImageUrl(data);
            s.setVideoUrl(data);
            //s.setFlag(flag);
            realm.commitTransaction();
            realm.close();
            CommonChatRealmHelper helper = new CommonChatRealmHelper(realm);
            if (helper.save(s)) {
                setAdapter();
            }
            else
            {
                Toast.makeText(CommonChattingAttachmentActivity.this, "Invalid Data", Toast.LENGTH_SHORT).show();
            }
            Log.d("path", data);
            Log.d("working realm", "yes....");
            Toast.makeText(getApplicationContext(),"Set Image URL"+data,Toast.LENGTH_LONG).show();
        }
        catch (Exception ex){
            Toast.makeText(getApplicationContext(),"Nope its not done",Toast.LENGTH_LONG).show();
        }
    }


    public void change1()
    {
        commonchat.setVisibility(View.GONE);
        functions.setVisibility(View.VISIBLE);
    }
    public void change2()
    {
        commonchat.setVisibility(View.VISIBLE);
        functions.setVisibility(View.GONE);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        realm.removeChangeListener(realmChangeListener);
        realm.close();}
}

我的适配器类

public class CCAA extends ArrayAdapter<CommonChat> {


    public CCAA(Context context, List<CommonChat> objects){
        super(context,0,objects);
        this.context = context;
        this.mInflater = LayoutInflater.from(context);
        contactList = objects;

    }

    @Override
    public CommonChat getItem(int position) {
        return contactList.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final CCAA.ViewHolder vh;
        if (convertView == null) {
            View view = mInflater.inflate(R.layout.item_commonchat, parent, false);
            vh = CCAA.ViewHolder.create((LinearLayout) view);
            view.setTag(vh);
        } else {
            vh = (CCAA.ViewHolder) convertView.getTag();
        }
        CommonChat s = getItem(position);

        if(s.getVideoUrl()!=null && s.getVideoUrl().length()>0)
        {
            vh.videoView.setVisibility(View.VISIBLE);
            vh.videoView.setVideoPath(s.getVideoUrl());
            vh.videoView.setMediaController(new MediaController(context));
            vh.videoView.start();
            Log.d("start error testing", "test");
            Toast.makeText(context, "Got Video URL" + s.getVideoUrl(), Toast.LENGTH_LONG).show();

        }


        if(vh.txtbeencnt!=null) {
            vh.txtbeencnt.setVisibility(View.VISIBLE);
            vh.imageView.setVisibility(View.GONE);
            vh.videoView.setVisibility(View.GONE);
            vh.txtbeencnt.setText(s.getDescription());
        }



        if(s.getImageUrl() != null && s.getImageUrl().length()>0) {

            if (s.getFlag().equalsIgnoreCase("gallery")) {
                vh.imageView.setVisibility(View.VISIBLE);
                vh.txtbeencnt.setVisibility(View.GONE);
                vh.videoView.setVisibility(View.GONE);
                Picasso.with(context).load(s.getImageUrl()).placeholder(R.mipmap.ic_launcher).into(vh.imageView);
                Toast.makeText(context, "Got Gallery Image URL" + s.getImageUrl(), Toast.LENGTH_LONG).show();
            }
            else if (s.getFlag().equalsIgnoreCase("camera")) {

                vh.imageView.setVisibility(View.VISIBLE);
                vh.txtbeencnt.setVisibility(View.GONE);
                vh.videoView.setVisibility(View.GONE);
                Bitmap bitmap = BitmapFactory.decodeFile(s.getImageUrl());
                vh.imageView.setImageBitmap(bitmap);
                Toast.makeText(context, "Got Camera Image URL" + s.getImageUrl(), Toast.LENGTH_LONG).show();
            }

        }


        return vh.rootView;
    }


    private static class ViewHolder {
        public final LinearLayout rootView;
        public final ImageView imageView;
        public final TextView txtbeencnt;
        public final VideoView videoView;
        public final TextView times;

        private ViewHolder(LinearLayout rootView, ImageView imageView, TextView txtbeencnt, VideoView videoView,RelativeTimeTextView times) {
            this.rootView = rootView;
            this.imageView = imageView;
            this.txtbeencnt = txtbeencnt;
            this.videoView = videoView;
            this.times = times;


        }

        public static CCAA.ViewHolder create(LinearLayout rootView) {
            ImageView imageView = (ImageView) rootView.findViewById(R.id.img);
            VideoView videoView = (VideoView) rootView.findViewById(R.id.videoView);
            TextView txtbeencnt = (TextView) rootView.findViewById(R.id.textdesc);
            RelativeTimeTextView times = (RelativeTimeTextView) rootView.findViewById(R.id.times);
            times.setReferenceTime(new Date().getTime());
            return new CCAA.ViewHolder(rootView, imageView, txtbeencnt, videoView,times);
        }

    }
}

我的Logcat

Unexpected activity pause without a matching activity resume. Logging data may be incorrect. Make sure you call activateApp from your Application's onCreate method
10-31 11:10:42.157 29588-29588/com.xitiz.xitizmobile W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
10-31 11:10:55.247 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:10:55.257 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:10:55.257 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:10:55.257 29588-29588/com.xitiz.xitizmobile D/path: file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4
10-31 11:10:55.257 29588-29588/com.xitiz.xitizmobile D/working realm: yes....
10-31 11:10:55.367 29588-29588/com.xitiz.xitizmobile D/start error testing: test
10-31 11:11:03.157 29588-29588/com.xitiz.xitizmobile W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
10-31 11:11:05.147 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.147 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:Intent { dat=content://com.android.providers.media.documents/document/video:146337 flg=0x1 }},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.157 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.157 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:Intent { dat=content://com.android.providers.media.documents/document/video:146337 flg=0x1 }},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.157 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.157 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:Intent { dat=content://com.android.providers.media.documents/document/video:146337 flg=0x1 }},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.167 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.167 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:Intent { dat=content://com.android.providers.media.documents/document/video:146337 flg=0x1 }},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.167 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:file:///storage/emulated/0/Pictures/MyCameraVideo/VID_20171031_111040.mp4},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.167 29588-29588/com.xitiz.xitizmobile D/Testing: CommonChat = [{description:null},{imageUrl:null},{videoUrl:Intent { dat=content://com.android.providers.media.documents/document/video:146337 flg=0x1 }},{MediaPathType:null},{flag:null},{date:null},{Latitude:null},{Longitude:null}]
10-31 11:11:05.167 29588-29588/com.xitiz.xitizmobile D/path: Intent { dat=content://com.android.providers.media.documents/document/video:146337 flg=0x1 }
10-31 11:11:05.167 29588-29588/com.xitiz.xitizmobile D/working realm: yes....
10-31 11:11:05.217 29588-29588/com.xitiz.xitizmobile D/start error testing: test
10-31 11:11:05.237 29588-29588/com.xitiz.xitizmobile D/start error testing: test

任何人都可以告诉我我错在哪里,因为我从摄影机和画廊获取视频路径,但问题是视频未在listview中显示,因为它返回空白。请看看我的编辑和完整的Logcat可以更好地了解错误。

1 个答案:

答案 0 :(得分:1)

我刚刚发过帖子{videoUrl:file:///storage/emulated/0/1509080683539.mp4}的路径不正确

if(s.getVideoUrl()!=null && s.getVideoUrl().length()>0){
      vh.videoView.setVisibility(View.VISIBLE);
      File videoFile = new File(s.getVideoUrl);
      vh.videoView.setVideoPath(videoFile.getAbsolutePath());
      vh.videoView.start();
      vh.videoView.setMediaController(newMediaController(context));
      Toast.makeText(context, "Got Video URL" + s.getVideoUrl(), Toast.LENGTH_LONG).show();
}

PostText :在阅读文件时,不要忘记添加权限android.permission.READ_EXTERNAL_STORAGE