多个videoview一个活动

时间:2014-04-14 21:44:50

标签: java android android-videoview

您好我正在创建健身应用程序并在一项活动中运行多个视频。第一个视频使用媒体控制器正常运行,但是以下3个视频无法播放此视频错误。如果有人可以帮助解决这个问题,那将会非常棒:)

    VideoView vid1, vid2, vid3, vid4;
    Button button6;

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

    vid1 = (VideoView)findViewById(R.id.videoView1);
    String uripath1 = "android.resource://" + getPackageName() + "/" + R.raw.inclinedbcurls;
    vid1.setVideoURI(Uri.parse(uripath1));

    MediaController mc1 = new MediaController(this);
    mc1.setMediaPlayer(vid1);
    vid1.setMediaController(mc1);

    vid2 = (VideoView)findViewById(R.id.videoView2);
    String uripath2 = "android.resource://" + getPackageName() + "/" + R.raw.dumbellbicepcurl;
    vid2.setVideoURI(Uri.parse(uripath2));

    MediaController mc2 = new MediaController(this);
    mc2.setMediaPlayer(vid2);
    vid2.setMediaController(mc2);

    vid3 = (VideoView)findViewById(R.id.videoView3);
    String uripath3 = "android.resource://" + getPackageName() + "/" + R.raw.dragcurl;
    vid3.setVideoURI(Uri.parse(uripath3));

    MediaController mc3 = new MediaController(this);
    mc3.setMediaPlayer(vid3);
    vid3.setMediaController(mc3);

    vid4 = (VideoView)findViewById(R.id.videoView4);
    String uripath4 = "android.resource://" + getPackageName() + "/" + R.raw.hammercurls;
    vid4.setVideoURI(Uri.parse(uripath4));

    MediaController mc4 = new MediaController(this);
    mc4.setMediaPlayer(vid4);
    vid4.setMediaController(mc4);



    <ScrollView android:layout_width="fill_parent"
     android:layout_height="500dp">

    <LinearLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Incline Dumbell Curl"
          android:layout_gravity="center_horizontal"
          android:textColor="#87CEFA"
          android:textSize="26dp" />

     <VideoView
          android:id="@+id/videoView1"
          android:layout_width="match_parent"
          android:layout_height="250dp" />

     <TextView
          android:id="@+id/textView2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Dumbell Bicep Curl"
          android:layout_gravity="center_horizontal"
          android:textColor="#87CEFA"
          android:textSize="26dp" />

     <VideoView
          android:id="@+id/videoView2"
          android:layout_width="match_parent"
          android:layout_height="250dp" />

     <TextView
          android:id="@+id/textView3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Drag Curl"
          android:layout_gravity="center_horizontal"
          android:textColor="#87CEFA"
          android:textSize="26dp" />

 <VideoView
          android:id="@+id/videoView3"
          android:layout_width="match_parent"
          android:layout_height="250dp" />

 <TextView
          android:id="@+id/textView4"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Hammer Curls"
          android:layout_gravity="center_horizontal"
          android:textColor="#87CEFA"
          android:textSize="26dp" />

      <VideoView
          android:id="@+id/videoView4"
          android:layout_width="match_parent"
          android:layout_height="250dp" />

     </LinearLayout>
     </ScrollView>

1 个答案:

答案 0 :(得分:1)

我建议在你的活动中使用3个不同的片段,并将每部电影放在一个片段中。 Android dev>Fragments