[Unity] Novice tutorial --- Android packaging, play local video

1. Install the Android module, find your installed one in the Unity Hub installation, then add the Android module, and wait for the installation to complete

 

 2. Create a new project, add Raw Image, this step is to play the video on the UI

 3. Add a video player to the Raw Image, and set the Source to URL. This step is for the convenience of later scripts to transfer the video path

 4. Create a new StreamingAssets folder and copy the video (MP4) into it

5. Create a new Script folder and create a new C# Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
using System.IO;

public class VideoPath : MonoBehaviour
{
    private VideoPlayer videoPlayer;
    // Start is called before the first frame update
    void Start()
    {
        videoPlayer = this.GetComponent<VideoPlayer>();
        videoPlayer.url = Path.Combine(Application.streamingAssetsPath, "video.mp4");
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

 6. Add script to Raw Image

 

7. The above is the preparatory work for the whole project, now do the Android modification

8. Add the AndroidManifest.xml file (you can skip this step if you have this file under the Assets\Plugins\Android folder)

Open File--Build Setting--check the scene is normal--PlayerSetting

 Find Player--PublishingSettings--build--custom Main Manifest--check

 9. Add read and write permissions

Open your project\Assets\Plugins\Android\AndroidManifest.xml, add

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

 

10. In fact, you can go here, you can go to the build setting to build, but it is best for you to change a configuration parameter.

 

 

 

Guess you like

Origin blog.csdn.net/qq_36251561/article/details/118990804