视频无法播放片段

时间:2018-02-23 19:42:46

标签: android

我正在制作GymExercises App,每个练习都是用不同的片段编写的 所以我想添加视频,以显示如何做运动,它编译,但没有显示任何人可以帮助我吗? PS我不需要播放,停止按钮和任何其他只是为了显示视频 这是我添加的代码

示例:

BenchFragment.java

 package com.Hristijan.Aleksandar.GymAssistant.Exercises;


import android.media.session.MediaController;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.VideoView;

import java.net.URL;


/**
 * A simple {@link Fragment} subclass.
 */
public class BenchFragment extends Fragment {


    public BenchFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_bench, container, false);
        VideoView view = (VideoView)rootView.findViewById(R.id.video_view);
        String path = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.bench1;
        view.setVideoURI(Uri.parse(path));
        view.start();
        return inflater.inflate(R.layout.fragment_bench, container, false);
    }

}

fragment_bench.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#000000"
    tools:context="com.Hristijan.Aleksandar.GymAssistant.Exercises.BenchFragment">

    <VideoView
        android:id="@+id/video_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        />


    <TableLayout
        android:layout_marginTop="20dp"
        android:layout_below="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:shrinkColumns="*">

        <TableRow>
            <TextView
                android:text="@string/group"
                android:background="@color/colorPrimary"
                android:layout_width="500dp"
                android:textColor="#ffffff"
                android:textStyle="italic"
                android:fontFamily="Arial"
                android:textSize="17sp"
                android:padding="5dip" />
        </TableRow>

        <TableRow>
            <TextView
                android:text="@string/bencbody"
                android:textStyle="italic"
                android:fontFamily="Arial"
                android:textSize="17sp"
                android:textColor="#ffffff"
                android:padding="3dip" />
        </TableRow>

        <TableRow>
            <TextView
                android:text="@string/description"
                android:textStyle="italic"
                android:fontFamily="Arial"
                android:textSize="19sp"
                android:background="@color/colorPrimary"
                android:textColor="#ffffff"
                android:padding="5dip" />
        </TableRow>

        <TableRow>
            <TextView
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:fontFamily="Arial"
                android:gravity="left"
                android:layout_marginTop="5dp"
                android:text="@string/stepone"
                android:textColor="@android:color/white"
                android:textSize="15sp"
                android:padding="3dip" />
        </TableRow>

        <TableRow>
            <TextView
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:fontFamily="Arial"
                android:layout_marginTop="5dp"
                android:gravity="left"
                android:text="@string/steptwo"
                android:textColor="@android:color/white"
                android:textSize="16sp"
                android:padding="3dip" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

0 个答案:

没有答案