Working on libVlc audio track

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@287 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2011-01-29 19:01:37 +00:00
parent 821b9d0f9c
commit 2a65e75c83
6 changed files with 90 additions and 81 deletions

View File

@ -37,6 +37,7 @@ namespace Nikse.SubtitleEdit.Forms
string _subtitleAlternateFileName;
string _fileName;
string _videoFileName;
int _videoAudioTrackNumber = -1;
public string VideoFileName
{
@ -894,6 +895,7 @@ namespace Nikse.SubtitleEdit.Forms
var visualSync = new VisualSync();
_formPositionsAndSizes.SetPositionAndSize(visualSync);
visualSync.VideoFileName = _videoFileName;
visualSync.AudioTrackNumber = _videoAudioTrackNumber;
SaveSubtitleListviewIndexes();
if (onlySelectedLines)
@ -908,6 +910,7 @@ namespace Nikse.SubtitleEdit.Forms
visualSync.Initialize(toolStripButtonVisualSync.Image as Bitmap, _subtitle, _fileName, _language.VisualSyncTitle, CurrentFrameRate);
}
mediaPlayer.Pause();
if (visualSync.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeVisualSync);
@ -1067,6 +1070,7 @@ namespace Nikse.SubtitleEdit.Forms
_findHelper = null;
_spellCheckForm = null;
_videoFileName = null;
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = Configuration.Settings.Language.General.NoVideoLoaded;
AudioWaveForm.WavePeaks = null;
AudioWaveForm.Invalidate();
@ -1136,6 +1140,7 @@ namespace Nikse.SubtitleEdit.Forms
_findHelper = null;
_spellCheckForm = null;
_videoFileName = null;
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = Configuration.Settings.Language.General.NoVideoLoaded;
AudioWaveForm.WavePeaks = null;
AudioWaveForm.Invalidate();
@ -1489,6 +1494,7 @@ namespace Nikse.SubtitleEdit.Forms
_findHelper = null;
_spellCheckForm = null;
_videoFileName = null;
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = Configuration.Settings.Language.General.NoVideoLoaded;
AudioWaveForm.WavePeaks = null;
AudioWaveForm.Invalidate();
@ -3721,39 +3727,7 @@ namespace Nikse.SubtitleEdit.Forms
{
int numberOfNewLines = textBoxListViewText.Text.Length - textBoxListViewText.Text.Replace(Environment.NewLine, " ").Length;
if (e.Modifiers == Keys.None && numberOfNewLines < 1 && textBoxListViewText.Text.Length > Configuration.Settings.General.SubtitleLineMaximumLength-5)
{
if (1 == 1) // auto break setting!
{
string newText;
if (textBoxListViewText.Text.Length > Configuration.Settings.General.SubtitleLineMaximumLength + 30)
{
newText = Utilities.AutoBreakLine(textBoxListViewText.Text);
}
else
{
int lastSpace = textBoxListViewText.Text.LastIndexOf(' ');
if (lastSpace > 0)
newText = textBoxListViewText.Text.Remove(lastSpace, 1).Insert(lastSpace, Environment.NewLine);
else
newText = textBoxListViewText.Text;
}
int autobreakIndex = newText.IndexOf(Environment.NewLine);
if (autobreakIndex > 0)
{
int selectionStart = textBoxListViewText.SelectionStart;
int selectionLength = textBoxListViewText.SelectionLength;
textBoxListViewText.Text = newText;
if (selectionStart > autobreakIndex)
selectionStart += Environment.NewLine.Length;
if (selectionStart >= 0)
textBoxListViewText.SelectionStart = selectionStart;
if (selectionLength >= 0)
textBoxListViewText.SelectionLength = selectionLength;
}
}
}
CheckAutoWrap(textBoxListViewText, e, numberOfNewLines);
if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.None && numberOfNewLines > 1)
{
@ -3800,6 +3774,43 @@ namespace Nikse.SubtitleEdit.Forms
_lastTextKeyDownTicks = DateTime.Now.Ticks;
}
private void CheckAutoWrap(TextBox textBox, KeyEventArgs e, int numberOfNewLines)
{
if (e.Modifiers == Keys.None && numberOfNewLines < 1 && textBox.Text.Length > Configuration.Settings.General.SubtitleLineMaximumLength - 3)
{
if (Configuration.Settings.General.AutoWrapLineWhileTyping) // only if auto-break-setting is true
{
string newText;
if (textBox.Text.Length > Configuration.Settings.General.SubtitleLineMaximumLength + 30)
{
newText = Utilities.AutoBreakLine(textBox.Text);
}
else
{
int lastSpace = textBox.Text.LastIndexOf(' ');
if (lastSpace > 0)
newText = textBox.Text.Remove(lastSpace, 1).Insert(lastSpace, Environment.NewLine);
else
newText = textBox.Text;
}
int autobreakIndex = newText.IndexOf(Environment.NewLine);
if (autobreakIndex > 0)
{
int selectionStart = textBox.SelectionStart;
int selectionLength = textBox.SelectionLength;
textBox.Text = newText;
if (selectionStart > autobreakIndex)
selectionStart += Environment.NewLine.Length;
if (selectionStart >= 0)
textBox.SelectionStart = selectionStart;
if (selectionLength >= 0)
textBox.SelectionLength = selectionLength;
}
}
}
}
private void SplitLineToolStripMenuItemClick(object sender, EventArgs e)
{
SplitSelectedParagraph(null);
@ -6110,7 +6121,7 @@ namespace Nikse.SubtitleEdit.Forms
if (importText.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
SyncPointsSync syncPointSync = new SyncPointsSync();
syncPointSync.Initialize(importText.FixedSubtitle, _fileName, importText.VideoFileName);
syncPointSync.Initialize(importText.FixedSubtitle, _fileName, importText.VideoFileName, _videoAudioTrackNumber);
if (syncPointSync.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
ResetSubtitle();
@ -6134,7 +6145,8 @@ namespace Nikse.SubtitleEdit.Forms
SyncPointsSync pointSync = new SyncPointsSync();
_formPositionsAndSizes.SetPositionAndSize(pointSync);
pointSync.Initialize(_subtitle, _fileName, _videoFileName);
pointSync.Initialize(_subtitle, _fileName, _videoFileName, _videoAudioTrackNumber);
mediaPlayer.Pause();
if (pointSync.ShowDialog(this) == DialogResult.OK)
{
_subtitleListViewIndex = -1;
@ -8797,6 +8809,7 @@ namespace Nikse.SubtitleEdit.Forms
mediaPlayer.VideoPlayer = null;
timer1.Stop();
_videoFileName = null;
_videoAudioTrackNumber = -1;
labelVideoInfo.Text = Configuration.Settings.Language.General.NoVideoLoaded;
AudioWaveForm.WavePeaks = null;
AudioWaveForm.Invalidate();
@ -8806,20 +8819,19 @@ namespace Nikse.SubtitleEdit.Forms
{
closeVideoToolStripMenuItem.Visible = !string.IsNullOrEmpty(_videoFileName);
toolStripMenuItemSetAudioTrack.Visible = false;
if (mediaPlayer.VideoPlayer != null && mediaPlayer.VideoPlayer is Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)
{
var libVlc = (Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)mediaPlayer.VideoPlayer;
int numberOfTracks = libVlc.AudioTrackCount;
int currentTrackNumber = libVlc.AudioTrackNumber;
if (numberOfTracks > 2)
_videoAudioTrackNumber = libVlc.AudioTrackNumber;
if (numberOfTracks > 1)
{
toolStripMenuItemSetAudioTrack.DropDownItems.Clear();
for (int i = 0; i < numberOfTracks-1; i++)
for (int i = 0; i < numberOfTracks; i++)
{
toolStripMenuItemSetAudioTrack.DropDownItems.Add((i + 1).ToString(), null, ChooseAudioTrack);
if (i+1 == currentTrackNumber)
if (i == _videoAudioTrackNumber)
toolStripMenuItemSetAudioTrack.DropDownItems[toolStripMenuItemSetAudioTrack.DropDownItems.Count - 1].Select();
}
toolStripMenuItemSetAudioTrack.Visible = true;
@ -8835,7 +8847,9 @@ namespace Nikse.SubtitleEdit.Forms
var item = sender as ToolStripItem;
int number = int.Parse(item.Text);
number--;
libVlc.AudioTrackNumber = number;
_videoAudioTrackNumber = number;
}
}
@ -8867,39 +8881,7 @@ namespace Nikse.SubtitleEdit.Forms
int numberOfNewLines = textBoxListViewTextAlternate.Text.Length - textBoxListViewTextAlternate.Text.Replace(Environment.NewLine, " ").Length;
if (e.Modifiers == Keys.None && numberOfNewLines < 1 && textBoxListViewTextAlternate.Text.Length >= Configuration.Settings.General.SubtitleLineMaximumLength)
{
if (1 == 1) // auto break setting!
{
string newText;
if (textBoxListViewTextAlternate.Text.Length > Configuration.Settings.General.SubtitleLineMaximumLength + 30)
{
newText = Utilities.AutoBreakLine(textBoxListViewTextAlternate.Text);
}
else
{
int lastSpace = textBoxListViewTextAlternate.Text.LastIndexOf(' ');
if (lastSpace > 0)
newText = textBoxListViewTextAlternate.Text.Remove(lastSpace, 1).Insert(lastSpace, Environment.NewLine);
else
newText = textBoxListViewTextAlternate.Text;
}
int autobreakIndex = newText.IndexOf(Environment.NewLine);
if (autobreakIndex > 0)
{
int selectionStart = textBoxListViewTextAlternate.SelectionStart;
int selectionLength = textBoxListViewTextAlternate.SelectionLength;
textBoxListViewTextAlternate.Text = newText;
if (selectionStart > autobreakIndex)
selectionStart += Environment.NewLine.Length;
if (selectionStart >= 0)
textBoxListViewTextAlternate.SelectionStart = selectionStart;
if (selectionLength >= 0)
textBoxListViewTextAlternate.SelectionLength = selectionLength;
}
}
}
CheckAutoWrap(textBoxListViewTextAlternate, e, numberOfNewLines);
if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.None && numberOfNewLines > 1)
{

View File

@ -684,7 +684,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2
CAAAAk1TRnQBSQFMAgEBAgEAATABAQEwAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAVABAQFQAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@ -14,6 +14,7 @@ namespace Nikse.SubtitleEdit.Forms
double _goBackPosition;
double _stopPosition = -1.0;
Subtitle _subtitle;
int _audioTrackNumber = -1;
public string VideoFileName { get; private set; }
@ -51,9 +52,10 @@ namespace Nikse.SubtitleEdit.Forms
get { return timeUpDownLine.TimeCode.TimeSpan; }
}
public void Initialize(Subtitle subtitle, string subtitleFileName, int index, string videoFileName)
public void Initialize(Subtitle subtitle, string subtitleFileName, int index, string videoFileName, int audioTrackNumber)
{
_subtitle = subtitle;
_audioTrackNumber = audioTrackNumber;
subtitleListView1.Fill(subtitle);
_guess = subtitle.Paragraphs[index].StartTime.TimeSpan;
subtitleListView1.Items[index].Selected = true;
@ -100,6 +102,7 @@ namespace Nikse.SubtitleEdit.Forms
openFileDialog1.FileName = string.Empty;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
_audioTrackNumber = -1;
openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
OpenVideo(openFileDialog1.FileName);
}
@ -143,6 +146,12 @@ namespace Nikse.SubtitleEdit.Forms
videoPlayerContainer1.VideoPlayer.CurrentPosition = _guess.TotalMilliseconds / 1000.0;
videoPlayerContainer1.RefreshProgressBar();
}
if (_audioTrackNumber > -1 && videoPlayerContainer1.VideoPlayer is Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)
{
var libVlc = (Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)videoPlayerContainer1.VideoPlayer;
libVlc.AudioTrackNumber = _audioTrackNumber;
}
}
private void timer1_Tick(object sender, EventArgs e)

View File

@ -21,6 +21,7 @@ namespace Nikse.SubtitleEdit.Forms
string _subtitleFileName;
string _videoFileName;
int _audioTrackNumber;
Subtitle _subtitle;
Subtitle _originalSubtitle;
System.Collections.Generic.SortedDictionary<int, TimeSpan> _syncronizationPoints = new SortedDictionary<int, TimeSpan>();
@ -65,12 +66,13 @@ namespace Nikse.SubtitleEdit.Forms
}
}
public void Initialize(Subtitle subtitle, string subtitleFileName, string videoFileName)
public void Initialize(Subtitle subtitle, string subtitleFileName, string videoFileName, int audioTrackNumber)
{
_subtitle = new Subtitle(subtitle);
_originalSubtitle = subtitle;
_subtitleFileName = subtitleFileName;
_videoFileName = videoFileName;
_audioTrackNumber = audioTrackNumber;
SubtitleListview1.Fill(subtitle);
if (SubtitleListview1.Items.Count > 0)
SubtitleListview1.Items[0].Selected = true;
@ -113,7 +115,7 @@ namespace Nikse.SubtitleEdit.Forms
{
SetSyncPoint getTime = new SetSyncPoint();
int index = SubtitleListview1.SelectedItems[0].Index;
getTime.Initialize(_subtitle, _subtitleFileName, index, _videoFileName);
getTime.Initialize(_subtitle, _subtitleFileName, index, _videoFileName, _audioTrackNumber);
if (getTime.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (_syncronizationPoints.ContainsKey(index))

View File

@ -26,6 +26,7 @@ namespace Nikse.SubtitleEdit.Forms
readonly LanguageStructure.General _languageGeneral;
public string VideoFileName { get; set; }
public int AudioTrackNumber { get; set; }
public bool OKPressed { get; set; }
@ -179,6 +180,12 @@ namespace Nikse.SubtitleEdit.Forms
Utilities.InitializeVideoPlayerAndContainer(MediaPlayerStart.VideoPlayer.VideoFileName, null, MediaPlayerEnd, VideoEndLoaded, VideoEndEnded);
}
timer1.Start();
if (AudioTrackNumber > -1 && MediaPlayerStart.VideoPlayer is Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)
{
var libVlc = (Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)MediaPlayerStart.VideoPlayer;
libVlc.AudioTrackNumber = AudioTrackNumber;
}
}
void VideoEndEnded(object sender, EventArgs e)
@ -194,6 +201,12 @@ namespace Nikse.SubtitleEdit.Forms
_endGoBackPosition = MediaPlayerEnd.CurrentPosition;
_endStopPosition = _endGoBackPosition + 0.1;
MediaPlayerEnd.Play();
if (AudioTrackNumber > -1 && MediaPlayerEnd.VideoPlayer is Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)
{
var libVlc = (Nikse.SubtitleEdit.Logic.VideoPlayers.LibVlc11xDynamic)MediaPlayerEnd.VideoPlayer;
libVlc.AudioTrackNumber = AudioTrackNumber;
}
}
private VideoInfo ShowVideoInfo(string fileName)
@ -458,6 +471,7 @@ namespace Nikse.SubtitleEdit.Forms
openFileDialog1.FileName = string.Empty;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
AudioTrackNumber = -1;
openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
OpenVideo(openFileDialog1.FileName);
}

View File

@ -318,7 +318,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{
get
{
return _libvlc_audio_get_track_count(_mediaPlayer);
return _libvlc_audio_get_track_count(_mediaPlayer)-1;
}
}
@ -327,11 +327,11 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{
get
{
return _libvlc_audio_get_track(_mediaPlayer);
return _libvlc_audio_get_track(_mediaPlayer)-1;
}
set
{
_libvlc_audio_set_track(_mediaPlayer, value);
_libvlc_audio_set_track(_mediaPlayer, value+1);
}
}
@ -481,9 +481,11 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (state == Ended)
{
// hack to make sure VLC is in ready state
Stop();
Play();
Pause();
OnVideoEnded.Invoke(_mediaPlayer, new EventArgs());
}
}