How to play multiple videos in different video ads in one action

Code example:

How to play two videos in one action

public class Two_videos extends Activity 
{
VideoView video1, video2;

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

VideoView video1= (VideoView) findViewById(R.id.video1);
              video1.setVideoPath("/mnt/sdcard/Movies/com.bnb.giggle/IMG_20130415184609.mp4");
            video1.start();

VideoView video2= (VideoView) findViewById(R.id.video2);
        video2.setVideoPath("/mnt/sdcard/Movies/com.bnb.giggle/IMG_20130415184608.mp4");
        video2.start();
   }
}

cannot play two videos at the same time.

+5
source share
4 answers

Playing multiple videos depends on the hardware, but if your device only supports one instance of the media player, then you must call your video .stopPlayBack () to play the video in another video ad. you can resume the video in the first video ad using its resume () method, but after stopping playback from the second.

+2
source

(HD-), , .

> , -.

+2

, . Android, , . .

+1

See the code below, here 4 videos are played in different videos in one action.

main_activity.xml

<LinearLayout 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:layout_weight="1.0"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="ycrathi.com.multiplevideoplay.MainActivity">

    <VideoView
        android:id="@+id/v1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.25" />

    <VideoView
        android:id="@+id/v2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.25" />

    <VideoView
        android:id="@+id/v3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.25" />

    <VideoView
        android:id="@+id/v4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.25" />


</LinearLayout>

MainActivity.java

    package ycrathi.com.multiplevideoplay;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        VideoView v1 = (VideoView) findViewById(R.id.v1);
        VideoView v2 = (VideoView) findViewById(R.id.v2);
        VideoView v3 = (VideoView) findViewById(R.id.v3);
        VideoView v4 = (VideoView) findViewById(R.id.v4);
        v1.setVideoURI(Uri.parse("http://192.168.1.1/Video/vid5.mp4"));
        v1.start();
        v1.requestFocus();
        v1.setKeepScreenOn(true);

        v2.setVideoURI(Uri.parse("http://192.168.1.1/Video/vid5.mp4"));
        v2.start();
        v2.requestFocus();
        v2.setKeepScreenOn(true);

        v3.setVideoURI(Uri.parse("http://192.168.1.1/Video/vid5.mp4"));
        v3.start();
        v3.requestFocus();
        v3.setKeepScreenOn(true);

        v4.setVideoURI(Uri.parse("http://192.168.1.1/Video/vid5.mp4"));
        v4.start();
        v4.requestFocus();
        v4.setKeepScreenOn(true);

    }
}

AndroidMenifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ycrathi.com.multiplevideoplay">
<uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
0
source

All Articles