Я пытаюсь воспроизвести видео в видеообъявлении, но показывается пустой видеореклама. Вид видео находится во всплывающем окне. Видео сохраняется во внешнем каталоге, и я использую setVideoPath
, чтобы передать путь к файлу.
Java-код для него:Android: видео не воспроизводится в Videoview
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();
}
И раскладка всплывающего окна выглядит следующим образом:
<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>
я упомянул другие решения и учебные пособия, но везде его сделал, как это только. Может ли кто-нибудь сказать мне, что мне не хватает?
EDIT:
Это путь к файлу, который проходит через:
/storage/emulated/0/Movies/issue_2016_12_30_15_31_13.mp4
EDIT2:
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
Правильно ли указан путь к файлу –
Да, чтобы проверить это, я ставлю условие if в код. – ashwinx
Проверьте формат видео https://www.macxdvd.com/mac-dvd-video-converter-how-to/supported-video-format-for-android.htm – sukumar