带有视频项目的列表视图 - 无法播放视频

时间:2014-07-22 09:52:29

标签: android-listview android-mediaplayer android-videoview listviewitem mediastore

首先我想说,我必须尝试找到像我一样的麻烦,但现有帖子中的问题有所不同,我会解释,好吧,我有一个带有ListView的主活动和一个按钮转到第二个活动。

该按钮调用第二个活动来创建一个项目,我有一个按钮通过意图 - mediastore.ACTION_VIDEO_CAPTURE拍摄视频并且工作正常。然后,我可以在VideoView中播放该视频,并可以3gp格式在SD Card上保存视频,然后返回Main Activity,然后使用新版本更新ListView项目。

ListView还有onItemClick方法,从那里我也可以转到Second Activity并执行我上面解释的内容。

我的问题是,如果我想编辑现有的项目(因此,如果我点击了某个项目),您知道,在第二个活动中,我会收到一条消息,其中显示Video cannot be played

这很奇怪,因为我使用相同的代码在onActivityResult中播放视频,而onCreate的{​​{1}}播放效果很好。它涉及相同的视频,但当我创建项目(第二个活动)工作正常但当我点击项目以显示第二个活动的布局显示该错误消息。

请注意,我在真正的设备上工作:Nexus 7。 没有路径/ uri问题,我检查了一下,我得到了正确的路径/ uri。

任何人都可以告诉我我错在哪里和/或我如何解决它?

提前致谢!

这是我的代码

Second Activity

通过@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video_detail_page); /** We get the values passed to the activity from the calling activity **/ /** determine the mode - add, update or delete **/ if (this.getIntent().getExtras() != null){ Bundle bundle = this.getIntent().getExtras(); mode = bundle.getString("mode"); id = bundle.getString("rowId"); video_path = bundle.getString("video_path"); } // we get references to all UI Elements and attach the listeners videoButton = (ImageButton)findViewById(R.id.take_video); title = (EditText)findViewById(R.id.edit_video_description); mVideoView = (VideoView)findViewById(R.id.thumbnail); videoButton.setOnClickListener(this); save = (Button) findViewById(R.id.save_note); save.setOnClickListener(this); delete = (Button) findViewById(R.id.delete_note); delete.setOnClickListener(this); // We disable delete option if we are in 'add' mode if (mode.trim().equalsIgnoreCase("add")){ delete.setEnabled(false); } else { // get the rowId for the specific Note loadVideoNoteInfo(); } } public void onClick(View v) { String myPath = ""; String extras = "Farm"; // We get "now" time Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); // get values from the EditText Fields String myNote = title.getText().toString(); // We check that the input 'NoteName' is not empty if (myNote.trim().equalsIgnoreCase("")){ Toast.makeText(getBaseContext(), "Please ENTER a NOT empty Note name", Toast.LENGTH_LONG).show(); return; } // We distinguish here until 3 differenButtons switch (v.getId()) { case R.id.save_note: ContentValues values = new ContentValues(); values.put(VideoNotesDb.KEY_GUID, myGuid); values.put(VideoNotesDb.KEY_NOTENAME, myNote); values.put(VideoNotesDb.KEY_PATH, video_path); values.put(VideoNotesDb.KEY_FARMNAME, extras); values.put(VideoNotesDb.KEY_MODIFICATION_DATE, timestamp.toString()); if (mode.trim().equalsIgnoreCase("add")){ // insert a record values.put(VideoNotesDb.KEY_CREATION_DATE, timestamp.toString()); getContentResolver().insert(MyContentProvider.CONTENT_URI, values); } else { // update a record Uri uri = Uri.parse(MyContentProvider.CONTENT_URI + "/" + id); getContentResolver().update(uri, values, null, null); } finish(); break; case R.id.delete_note: // delete a record Log.i("TAG", "videoNoteEdit:: onClick delete_note"); Uri uri = Uri.parse(MyContentProvider.CONTENT_URI + "/" + id); getContentResolver().delete(uri, null, null); finish(); break; case R.id.take_video : // Take a video dispatchTakeVideoIntent(); break; } } private void loadVideoNoteInfo(){ String[] projection = { VideoNotesDb.KEY_ROWID, VideoNotesDb.KEY_NOTENAME, VideoNotesDb.KEY_FIELDNAME, VideoNotesDb.KEY_FARMNAME, VideoNotesDb.KEY_PATH, VideoNotesDb.KEY_CREATION_DATE, VideoNotesDb.KEY_MODIFICATION_DATE }; Uri uri = Uri.parse(MyContentProvider.CONTENT_URI + "/" + id); Cursor cursor = getContentResolver().query(uri, projection, null, null, null); if (cursor != null) { cursor.moveToFirst(); myTitle = cursor.getString(cursor.getColumnIndexOrThrow(VideoNotesDb.KEY_NOTENAME)); myPath = cursor.getString(cursor.getColumnIndexOrThrow(VideoNotesDb.KEY_PATH)); handleVideo(Uri.parse(myPath)); // <= Cause of this line that `Video cannot be played` appears title.setText(myTitle); } } 拍摄视频的整个过程。它工作正常!

Mediastore.ACTION_VIDEO_CAPTURE

重演:我可以通过活动的private void dispatchTakeVideoIntent() { File f = null; Intent takePictureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); try { f = setupVideoFile(); mCurrentPhotoPath = f.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); } catch (Exception e) { e.printStackTrace(); f = null; mCurrentPhotoPath = null; } Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_VIDEO_CAPTURE: mVideoUri = data.getData(); handleVideo(mVideoUri); break; } } private void handleVideo(Uri uri) { mVideoView.setMediaController(new MediaController(this)); mVideoView.setVideoURI(uri); mVideoView.requestFocus(); mVideoView.start(); } 中的.3gp播放Mediastore.ACTION_VIDEO_CAPTURE视频,但是当我试用onActivityResult时要返回该活动,使用相同的代码播放此活动的Mediastore.ACTION_VIDEO_CAPTURE中的视频,我会收到消息onCreate

0 个答案:

没有答案