[英]Android : Video not playing in Videoview
I am trying to play video inside a videoview but a blank video view is showing. 我正在尝试在videoview中播放视频,但显示空白视频视图。 The video view is inside a popup window.
视频视图在弹出窗口中。 The video is stored in the external directory and I am using
setVideoPath
to pass the file path. 视频存储在外部目录中,我正在使用
setVideoPath
传递文件路径。
java code for it: 的Java代码:
final View videoPopupView = getLayoutInflater().inflate(R.layout.popup_video_preview, null);
Button cancelVideo = (Button)videoPopupView.findViewById(R.id.cancelVideo);
Button confirmVideo = (Button)videoPopupView.findViewById(R.id.confirmVideo);
final VideoView videoView = (VideoView)videoPopupView.findViewById(R.id.popupVideoView);
final PopupWindow video_popup_window = new PopupWindow(videoPopupView,RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT, true);
if(new File(attachment_Path+attachment_Name).exists())
{
video_popup_window.showAtLocation(videoPopupView, 1, 0, 0);
videoView.setVideoPath(attachment_Path+attachment_Name);
if (mediaController == null) {
mediaController = new android.widget.MediaController(MainActivity.this);
}
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
And the popup layout looks like this: 弹出布局如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000">
<VideoView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/popupVideoView"
android:background="@drawable/blackborder"
android:layout_marginTop="25dp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal">
<Button
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/cancelVideo"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="Attach"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/confirmVideo"
android:layout_alignParentBottom="true" />
</LinearLayout>
</LinearLayout>
I have referred other solutions and tutorials but everywhere its done like this only. 我已经提到了其他解决方案和教程,但是到处都是这样。 Can someone tell me what is it that I am missing?
有人可以告诉我我想念的是什么吗?
EDIT: 编辑:
This is the file path that is going through : 这是正在通过的文件路径:
/storage/emulated/0/Movies/issue_2016_12_30_15_31_13.mp4
EDIT2: 编辑2:
Codec Info: 编解码器信息:
Stream 0
Type: Video
Codec: H264 - MPEG-4 AVC (part 10) (avc1)
Language: English
Resolution: 720x1280
Frame rate: 5.564744
Decoded format: Planar 4:2:0 YUV
Stream 1
Type: Audio
Codec: AMR narrow band (samr)
Language: English
Channels: Mono
Sample rate: 8000 Hz
Bits per sample: 32
You have to go for a custom dialog, add this code - 您必须进入自定义对话框,添加以下代码-
Dialog mVideoDialog ;
VideoView mVideoFullScreen;
MediaController controller;
Create a method -
mVideoDialog = new Dialog(this);
mVideoDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mVideoDialog.setContentView(R.layout.dialog);
mVideoDialog.setOnKeyListener(this);
mVideoFullScreen = (VideoView) mVideoDialog.findViewById(R.id.videoview1);
controller = new MediaController(this);
showVideo();
}
//Show video method to play the video file -
public void showVideo() {
// TODO Auto-generated method stub
mVideoDialog.show();
mVideoFullScreen.setVideoPath("file:///sdcard/video file name.m4v");
controller.setMediaPlayer(mVideoFullScreen);
mVideoFullScreen.setMediaController(controller);
mVideoFullScreen.requestFocus();
mVideoFullScreen.start();
}
try this code 试试这个代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.