protected void AddTrack(ITrack track, bool isExternal = false) { _tracks.Add(track); if (isExternal) { _externalTracks.Add(track); } else { _internalTracks.Add(track); } if (track.TrackType == TrackType.Audio) { // Update volume settings if it's an audio track ((AudioTrack)track).Volume = _audioVolume; ((AudioTrack)track).Balance = _audioBalance; if (!isExternal && SupportsAudioTrackSwitching()) { if (_mainAudioTrack != null) { // The main audio track has already been found ((AudioTrack)track).Mute = true; } else { // First audio track found . now the main one _mainAudioTrack = (AudioTrack)track; _mainAudioTrack.Mute = false; } } } else if (track.TrackType == TrackType.Video) { // If this track has a better time, update _nextVideoTrack if (_nextVideoTrack == null || ((VideoTrack)track).GetNextFrameStartTime() < _nextVideoTrack.GetNextFrameStartTime()) { _nextVideoTrack = (VideoTrack)track; } } // Keep the track paused if we're paused if (IsPaused) { track.Pause(true); } // Start the track if we're playing if (IsPlaying && track.TrackType == TrackType.Audio) { ((AudioTrack)track).Start(); } }
private VideoTrack FindNextVideoTrack() { _nextVideoTrack = null; uint bestTime = 0xFFFFFFFF; foreach (var t in _tracks) { if (t.TrackType == TrackType.Video && !t.EndOfTrack) { VideoTrack track = (VideoTrack)t; uint time = track.GetNextFrameStartTime(); if (time < bestTime) { bestTime = time; _nextVideoTrack = track; } } } return(_nextVideoTrack); }