public void OpenVideoFile(MediaPlaylist.MediaItem mediaItem) { bool isMediaAlreadyLoaded = false; if (NextPlayer.MediaPath == mediaItem.mediaPath) { isMediaAlreadyLoaded = true; } if (!mediaItem.isOverrideTransition) { SetTransition(_defaultTransition, _defaultTransitionDuration, _defaultTransitionEasing); } else { SetTransition(mediaItem.overrideTransition, mediaItem.overrideTransitionDuration, mediaItem.overrideTransitionEasing); } this.Loop = NextPlayer.Loop = mediaItem.loop; NextPlayer.MediaPath = new MediaPath(mediaItem.mediaPath); this.MediaPath = new MediaPath(mediaItem.mediaPath); NextPlayer.AudioMuted = _playlistAudioMuted; NextPlayer.AudioVolume = _playlistAudioVolume; if (_transitionTimer < _currentTransitionDuration && _currentTransition != Transition.None) { NextPlayer.AudioVolume = 0f; } if (isMediaAlreadyLoaded) { NextPlayer.Rewind(false); if (_nextItem.startMode == StartMode.Immediate) { NextPlayer.Play(); } // TODO: We probably want to wait until the new frame arrives before swapping after a Rewind() SwapPlayers(); } else { if (string.IsNullOrEmpty(NextPlayer.MediaPath.Path)) { NextPlayer.CloseMedia(); } else { NextPlayer.OpenMedia(NextPlayer.MediaPath.PathType, NextPlayer.MediaPath.Path, _nextItem.startMode == StartMode.Immediate); } } }
protected override void Update() { if (!Application.isPlaying) { return; } if (!IsPaused()) { if (IsTransitioning()) { _transitionTimer += Time.deltaTime; float t = _easeFunc(Mathf.Clamp01(_transitionTimer / _currentTransitionDuration)); // Fade the audio volume NextPlayer.AudioVolume = (1f - t) * this.AudioVolume; CurrentPlayer.AudioVolume = t * this.AudioVolume; // TODO: support going from mono to stereo // TODO: support videos of different aspect ratios by rendering with scaling to fit // This can be done by blitting twice, once for each eye // If the stereo mode is different for playera/b then both should be set to stereo during the transition // if (CurrentPlayer.m_StereoPacking == StereoPacking.TopBottom).... _material.SetFloat(PropFade.Id, t); _rt.DiscardContents(); Graphics.Blit(GetCurrentTexture(), _rt, _material); // After the transition is now complete, close/pause the previous video if required bool isTransitioning = IsTransitioning(); if (!isTransitioning) { if (_autoCloseVideo) { if (NextPlayer != null) { NextPlayer.MediaPath.Path = string.Empty; NextPlayer.CloseMedia(); } } else if (!_pausePreviousOnTransition) { if (NextPlayer != null && NextPlayer.Control.IsPlaying()) { NextPlayer.Pause(); } } } } else { if (_playlistAutoProgress && _nextItem == null && _currentItem != null && _currentItem.progressMode == ProgressMode.BeforeFinish && Control != null && Control.HasMetaData() && Control.GetCurrentTime() >= (Info.GetDuration() - (_currentItem.progressTimeSeconds))) { this.NextItem(); } else if (_playlistAutoProgress && _currentItem == null) { JumpToItem(_playlistIndex); } } } base.Update(); }