void Awake()
 {
     if (execute)
     {
         videoPlayer = GetComponent <MediaPlayer>();
         videoPlayer.Events.AddListener(OnVideoEvent);
     }
 }
    public void _Before()
    {
        // Camera setup
        camObj = new GameObject("Camera");
        camObj.AddComponent <Camera>();
        camObj.transform.Translate(0, 0, -3);

        // Light setup
        light = new GameObject("Light");
        Light l = light.AddComponent <Light>();

        l.type = LightType.Directional;

        // Player Setup
        playerObj = new GameObject("Video Player");
        player    = playerObj.AddComponent <VimeoPlayer>();
        player.selectedResolution = StreamingResolution.x360p;
        player.autoPlay           = false;

        // AVPro setup
        mediaPlayer             = playerObj.AddComponent <RenderHeads.Media.AVProVideo.MediaPlayer>();
        mediaPlayer.m_AutoStart = false;
        mediaPlayer.m_AutoOpen  = false;
        player.videoPlayerType  = VideoPlayerType.AVProVideo;
        player.mediaPlayer      = mediaPlayer;

        // Screen setup
        screenObj          = GameObject.CreatePrimitive(PrimitiveType.Cube);
        player.videoScreen = screenObj;
        camObj.transform.LookAt(playerObj.transform);

        // Attach avpro to screen
        RenderHeads.Media.AVProVideo.ApplyToMesh applyToMesh = playerObj.AddComponent <RenderHeads.Media.AVProVideo.ApplyToMesh>();
        applyToMesh.Player       = mediaPlayer;
        applyToMesh.MeshRenderer = screenObj.GetComponent <MeshRenderer>();

        triggered = false;
        elapsed   = 0;
    }
Example #3
0
 // Callback function to handle events
 private void OnMediaPlayerEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
 {
     AddEvent(et);
 }
        private void SwapPlayers()
        {
            // Pause the previously playing video
            // This is useful for systems that will struggle to play 2 videos at once
            if (_pausePreviousOnTransition)
            {
                CurrentPlayer.Pause();
            }

            // Tell listeners that the playlist item has changed
            Events.Invoke(this, MediaPlayerEvent.EventType.PlaylistItemChanged, ErrorCode.None);

            // Start the transition
            if (_currentTransition != Transition.None)
            {
                // Create a new transition texture if required
                Texture currentTexture = GetCurrentTexture();
                Texture nextTexture    = GetNextTexture();
                if (currentTexture != null && nextTexture != null)
                {
                    int maxWidth  = Mathf.Max(nextTexture.width, currentTexture.width);
                    int maxHeight = Mathf.Max(nextTexture.height, currentTexture.height);
                    if (_rt != null)
                    {
                        if (_rt.width != maxWidth || _rt.height != maxHeight)
                        {
                            RenderTexture.ReleaseTemporary(_rt = null);
                        }
                    }

                    if (_rt == null)
                    {
                        _rt = RenderTexture.GetTemporary(maxWidth, maxHeight, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 1);
                        Graphics.Blit(currentTexture, _rt);
                    }

                    _material.SetTexture(_propFromTex, currentTexture);

                    _easeFunc        = Easing.GetFunction(_currentTransitionEasing);
                    _transitionTimer = 0f;
                }
                else
                {
                    _transitionTimer = _currentTransitionDuration;

                    if (_autoCloseVideo)
                    {
                        CurrentPlayer.CloseVideo();
                    }
                }
            }

            // Swap the videos
            if (NextPlayer == _playerA)
            {
                _nextPlayer = _playerB;
            }
            else
            {
                _nextPlayer = _playerA;
            }

            // Swap the items
            _currentItem = _nextItem;
            _nextItem    = null;
        }
        public void RequestAudio(AudioOutput _outputComponent, MediaPlayer mediaPlayer, float[] data, int channelMask, int totalChannels, AudioOutput.AudioOutputMode audioOutputMode)
        {
            if (mediaPlayer == null || mediaPlayer.Control == null || !mediaPlayer.Control.IsPlaying())
            {
                return;
            }

            int channels = mediaPlayer.Control.GetNumAudioChannels();
            if(channels <= 0)
            {
                return;
            }

            //total samples requested should be multiple of channels
            #if UNITY_5 || UNITY_5_4_OR_NEWER
            Debug.Assert(data.Length % totalChannels == 0);
            #endif

            if (!_accessTrackers.ContainsKey(mediaPlayer))
            {
                _accessTrackers[mediaPlayer] = new HashSet<AudioOutput>();
            }

            //requests data if it hasn't been requested yet for the current cycle
            if (_accessTrackers[mediaPlayer].Contains(_outputComponent) || _accessTrackers[mediaPlayer].Count == 0 || _pcmData[mediaPlayer] == null)
            {
                _accessTrackers[mediaPlayer].Clear();

                int actualDataRequired = data.Length / totalChannels * channels;
                _pcmData[mediaPlayer] = new float[actualDataRequired];

                GrabAudio(mediaPlayer, _pcmData[mediaPlayer], channels);

                _accessTrackers[mediaPlayer].Add(_outputComponent);
            }

            //calculate how many samples and what channels are needed and then copy over the data
            int samples = Math.Min(data.Length / totalChannels, _pcmData[mediaPlayer].Length / channels);
            int storedPos = 0;
            int requestedPos = 0;

            //multiple mode, copies over audio from desired channels into the same channels on the audiosource
            if (audioOutputMode == AudioOutput.AudioOutputMode.Multiple)
            {
                int lesserChannels = Math.Min(channels, totalChannels);

                for (int i = 0; i < samples; ++i)
                {
                    for (int j = 0; j < lesserChannels; ++j)
                    {
                        if ((1 << j & channelMask) > 0)
                        {
                            data[requestedPos + j] = _pcmData[mediaPlayer][storedPos + j];
                        }
                    }

                    storedPos += channels;
                    requestedPos += totalChannels;
                }
            }

            //Mono mode, copies over single channel to all output channels
            else if(audioOutputMode == AudioOutput.AudioOutputMode.Single)
            {
                int desiredChannel = 0;

                for (int i = 0; i < 8; ++i)
                {
                    if ((channelMask & (1 << i)) > 0)
                    {
                        desiredChannel = i;
                        break;
                    }
                }

                if(desiredChannel < channels)
                {
                    for (int i = 0; i < samples; ++i)
                    {
                        for (int j = 0; j < totalChannels; ++j)
                        {
                            data[requestedPos + j] = _pcmData[mediaPlayer][storedPos + desiredChannel];
                        }

                        storedPos += channels;
                        requestedPos += totalChannels;
                    }
                }
            }
        }
 private void GrabAudio(MediaPlayer player, float[] data, int channels)
 {
     player.Control.GrabAudio(data, data.Length, channels);
 }