LoginSignup
3
4

More than 5 years have passed since last update.

Unityで動画再生

Posted at

概要

Unityで動画再生したい
そこで、最初はUnity標準のMovieTextureだったかを使った。
シークできないことや、再生の動作が重いなどの問題多数出てきた。
そこで他の方法で動画再生させようとした話である。

解決方法

AV Pro なるAssetがある。
https://www.assetstore.unity3d.com/jp/#!/content/56355
これのお試し版があったので、それで実験してみた。

実験環境

詳細
OS Mac OSX 10.11
Unity 5.4.2f2

実験結果

  • シーク移動
  • 絶対アドレス指定で、動画再生
  • 再生開始時の安定した動作

ソースコード

source
using UnityEngine;
using System.Collections;
using RenderHeads.Media.AVProVideo;

// Media Player(Script)に、このクラスをAdd Componentしてください。
//
//
//
public class MyMediaPlayer : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }
    void Update () {
        if (Input.GetKeyUp("a")){
       //シーク移動
            MediaPlayer mediaplayer = this.gameObject.GetComponent<MediaPlayer> ();//自分のコンポーネントから
            IMediaControl control = mediaplayer.Control;
            control.Seek (200000.0f);//単位は、ミリセカンド(1000分の1秒)

            Debug.Log ("A Key UP");

         }


        if (Input.GetKeyUp("n")){
            MediaPlayer mediaplayer = this.gameObject.GetComponent<MediaPlayer> ();
            IMediaControl control = mediaplayer.Control;
            control.Stop ();
            control.CloseVideo ();

            control.OpenVideoFromFile ("/Users/”ユーザ名”/Movies/test/test2.mp4",0);//絶対アドレスで再生する動画指定


            //control.Play (); //ここで再生しても再生しない。しばらくたったら、再生実行すると再生される。

            Debug.Log ("N Key Down");

        }
    }
}

シーク移動

シーク移動して再生継続

再生開始時の安定した動作

特に何か変更していないが、AV Proにしてからは特に問題になっていない

あとでなんかできたら追加

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4