4

Unityでムービー再生をするときは、MovieTextureを使うのが基本だと思います。

http://docs-jp.unity3d.com/Documentation/Components/class-MovieTexture.html

ですが、これはProライセンス(iOSProとAndroidProも必須?)のため、できればBasicライセンスでも動かせる実装をしたいと思っています。 Unityでムービー再生をUnityProライセンスなしで行う方法やAssetがあったらお願いします。

1
  • 追加情報として、Unity 5からは無料版でもMovie Textureが使用できるようになったようです。 2015年7月6日 5:23

2 件の回答 2

5

プラグインになりますがiOSのWebViewで動画再生してみたことがあります。
https://www.youtube.com/watch?v=Wxd6dUXsq9g&t=50s
WebViewを Objective-C で3Dライクに苦労して傾けてあります。

WebPlayerですとJavascript経由でYoutubeの動画などが再生できます。
テスト画面
ScreenShot

Unity WebPlayer
https://museum3d.azurewebsites.net/v1/fb/170251749687065_103246

参考までに、テストしたJavascriptのコードです。

function showVideo(videoId, source){
  $("#video").show();
  var el = document.getElementById("video");
  if (source == "youtube") {
    var html = '<iframe width="560" height="315" src="https://www.youtube.com/embed/';
    html += videoId + '?wmode=opaque&autoplay=1&enablejsapi=1" frameborder="0" allowfullscreen></iframe>';
    var userAgent = window.navigator.userAgent.toLowerCase();
    console.log("showVideo: userAgent" + userAgent);
    if (userAgent.indexOf('chrome') != -1) {
      console.log("showVideo: userAgent" + userAgent);
    } else if (userAgent.indexOf('safari') != -1) {
      html ='<object width="560" height="315">';
      html +='<param name="movie" value="http://www.youtube.com/v/';
      html += videoId + '?version=3&amp;hl=en_US&amp;rel=0"></param>';
      html +='<param name="allowFullScreen" value="true"></param>';
      html +='<param name="allowscriptaccess" value="always"></param>';
      html +='<embed src="http://www.youtube.com/v/';
      html += videoId + '?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash"';
      html +=' width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed>';
      html +='</object>';
    }
  } else if (source == "xxx") {
    console.log("showVideo:" + source);
  }
    el.innerHTML = html 
}

unity の生成する html に
<div id="video" style="opacity:0.8;"></div>
を追加。

3D空間にあわせて
http://thewebrocks.com/demos/3D-css-tester/
を参考にCSSを作成することで動画スクリーンを傾け(uGUIのカメラのような設定)。

 <style>
 #logosVideo {
   position:absolute;
   -webkit-perspective: 700px;
   perspective: 700px; 
 }
 #cubeVideo {
   display: block;  position: relative;  margin: 30px auto;
   height: 315px;  width: 560px;
   -webkit-transform-style: preserve-3d;
   -webkit-transform:  rotateY(30deg) rotateZ(0.5deg) rotateX(0.5deg);
   transform-style: preserve-3d;
   transform:  rotateY(30deg) rotateZ(0.5deg) rotateX(0.5deg);
 }
 </style>

<div id="logosVideo">
   <div id="cubeVideo">
     <div id="video" style="opacity:0.8;"></div>
  <div>
</div>`

画面上に動画を表示すると uGUI のマウス操作と干渉するので、動画用に設定した領域は表示しないときは確実に閉じておく必要があります。

$("#video").hide();

Youtube の表示 on/off は以下を参照。
https://stackoverflow.com/questions/8667882/how-to-pause-a-youtube-player-when-hiding-the-iframe

1
  • youtube でパラメータに &autoplay=1 を追加するとautoplay するようなので(以前、試したときは動作しなかったはずなのですが...)BMG としても使えるかもしれません。 2015年1月10日 11:08
2

調べた限り、これはUnityFreeで使えそうでした。(未確認・未購入)

https://www.assetstore.unity3d.com/jp/#!/content/15580

MPEGなどの純粋な動画ファイルではなく、MJPG(動画を大量のJPGテクスチャの形にするという形式)のようです。この形式だとMPEG等に比べて、ファイルサイズやメモリ消費等が大きいかもしれないですね。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。