mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
Added audio track functionality to mpv player
This commit is contained in:
parent
465a80815f
commit
9485fd9350
@ -1749,6 +1749,7 @@ can edit in same subtitle file (collaboration)</Information>
|
||||
<Title>Settings for mpv</Title>
|
||||
<DownloadMpv>Download mpv dll</DownloadMpv>
|
||||
<DownloadMpvFailed>Unable to download mpv - please re-try later!</DownloadMpvFailed>
|
||||
<DownloadMpvOk>The mpv dll file was downloaded and is ready for use.</DownloadMpvOk>
|
||||
</SettingsMpv>
|
||||
<SetVideoOffset>
|
||||
<Title>Set video offset</Title>
|
||||
|
@ -4696,6 +4696,9 @@ namespace Nikse.SubtitleEdit.Core
|
||||
case "SettingsMpv/DownloadMpvFailed":
|
||||
language.SettingsMpv.DownloadMpvFailed = reader.Value;
|
||||
break;
|
||||
case "SettingsMpv/DownloadMpvOk":
|
||||
language.SettingsMpv.DownloadMpvOk = reader.Value;
|
||||
break;
|
||||
case "SetVideoOffset/Title":
|
||||
language.SetVideoOffset.Title = reader.Value;
|
||||
break;
|
||||
|
@ -290,5 +290,53 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<string> ReadObjectArray(string text)
|
||||
{
|
||||
var list = new List<string>();
|
||||
text = text.Trim();
|
||||
if (text.StartsWith('[') && text.EndsWith(']'))
|
||||
{
|
||||
text = text.Trim('[', ']').Trim();
|
||||
int onCount = 0;
|
||||
bool keepNext = false;
|
||||
var sb = new StringBuilder();
|
||||
foreach (var c in text)
|
||||
{
|
||||
if (keepNext)
|
||||
{
|
||||
sb.Append(c);
|
||||
keepNext = false;
|
||||
}
|
||||
else if (c == '\\')
|
||||
{
|
||||
sb.Append(c);
|
||||
keepNext = true;
|
||||
}
|
||||
else if (c == '{')
|
||||
{
|
||||
sb.Append(c);
|
||||
onCount++;
|
||||
}
|
||||
else if (c == '}')
|
||||
{
|
||||
sb.Append(c);
|
||||
onCount--;
|
||||
}
|
||||
else if (c == ',' && onCount == 0)
|
||||
{
|
||||
list.Add(sb.ToString().Trim());
|
||||
sb.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(c);
|
||||
}
|
||||
}
|
||||
if (sb.Length > 0)
|
||||
list.Add(sb.ToString().Trim());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -16618,6 +16618,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
toolStripMenuItemSetAudioTrack.Visible = false;
|
||||
var libVlc = mediaPlayer.VideoPlayer as LibVlcDynamic;
|
||||
var libMpv = mediaPlayer.VideoPlayer as LibMpvDynamic;
|
||||
if (libVlc != null)
|
||||
{
|
||||
int numberOfTracks = libVlc.AudioTrackCount;
|
||||
@ -16634,6 +16635,22 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
toolStripMenuItemSetAudioTrack.Visible = true;
|
||||
}
|
||||
}
|
||||
else if (libMpv != null)
|
||||
{
|
||||
int numberOfTracks = libMpv.AudioTrackCount;
|
||||
_videoAudioTrackNumber = libMpv.AudioTrackNumber;
|
||||
if (numberOfTracks > 1)
|
||||
{
|
||||
toolStripMenuItemSetAudioTrack.DropDownItems.Clear();
|
||||
for (int i = 0; i < numberOfTracks; i++)
|
||||
{
|
||||
toolStripMenuItemSetAudioTrack.DropDownItems.Add((i + 1).ToString(CultureInfo.InvariantCulture), null, ChooseAudioTrack);
|
||||
if (i == _videoAudioTrackNumber)
|
||||
toolStripMenuItemSetAudioTrack.DropDownItems[toolStripMenuItemSetAudioTrack.DropDownItems.Count - 1].Select();
|
||||
}
|
||||
toolStripMenuItemSetAudioTrack.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mediaPlayer.VideoPlayer != null && audioVisualizer != null && audioVisualizer.WavePeaks != null && audioVisualizer.WavePeaks.Peaks.Count > 0)
|
||||
{
|
||||
@ -16650,15 +16667,23 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
private void ChooseAudioTrack(object sender, EventArgs e)
|
||||
{
|
||||
var libVlc = mediaPlayer.VideoPlayer as LibVlcDynamic;
|
||||
var libMpv = mediaPlayer.VideoPlayer as LibMpvDynamic;
|
||||
if (libVlc != null)
|
||||
{
|
||||
var item = sender as ToolStripItem;
|
||||
|
||||
int number = int.Parse(item.Text);
|
||||
number--;
|
||||
libVlc.AudioTrackNumber = number;
|
||||
_videoAudioTrackNumber = number;
|
||||
}
|
||||
else if (libMpv != null)
|
||||
{
|
||||
var item = sender as ToolStripItem;
|
||||
int number = int.Parse(item.Text);
|
||||
number--;
|
||||
libMpv.AudioTrackNumber = number;
|
||||
_videoAudioTrackNumber = number;
|
||||
}
|
||||
}
|
||||
|
||||
private void textBoxListViewTextAlternate_TextChanged(object sender, EventArgs e)
|
||||
|
@ -163,6 +163,11 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
var libVlc = (LibVlcDynamic)videoPlayerContainer1.VideoPlayer;
|
||||
libVlc.AudioTrackNumber = _audioTrackNumber;
|
||||
}
|
||||
else if (_audioTrackNumber >= 0 && videoPlayerContainer1.VideoPlayer is LibMpvDynamic)
|
||||
{
|
||||
var libMpv = (LibMpvDynamic)videoPlayerContainer1.VideoPlayer;
|
||||
libMpv.AudioTrackNumber = _audioTrackNumber;
|
||||
}
|
||||
}
|
||||
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
|
@ -191,6 +191,11 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
var libVlc = (LibVlcDynamic)MediaPlayerStart.VideoPlayer;
|
||||
libVlc.AudioTrackNumber = AudioTrackNumber;
|
||||
}
|
||||
else if (AudioTrackNumber >= 0 && MediaPlayerStart.VideoPlayer is LibMpvDynamic)
|
||||
{
|
||||
var libMpv = (LibMpvDynamic)MediaPlayerStart.VideoPlayer;
|
||||
libMpv.AudioTrackNumber = AudioTrackNumber;
|
||||
}
|
||||
}
|
||||
|
||||
private void VideoEndEnded(object sender, EventArgs e)
|
||||
@ -212,6 +217,11 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
var libVlc = (LibVlcDynamic)MediaPlayerEnd.VideoPlayer;
|
||||
libVlc.AudioTrackNumber = AudioTrackNumber;
|
||||
}
|
||||
else if (AudioTrackNumber >= 0 && MediaPlayerEnd.VideoPlayer is LibMpvDynamic)
|
||||
{
|
||||
var libMpv = (LibMpvDynamic)MediaPlayerEnd.VideoPlayer;
|
||||
libMpv.AudioTrackNumber = AudioTrackNumber;
|
||||
}
|
||||
}
|
||||
|
||||
private VideoInfo ShowVideoInfo(string fileName)
|
||||
|
@ -1,10 +1,12 @@
|
||||
using Nikse.SubtitleEdit.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Nikse.SubtitleEdit.Core.SubtitleFormats;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.VideoPlayers
|
||||
{
|
||||
@ -237,26 +239,54 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
|
||||
get { return !IsPaused; }
|
||||
}
|
||||
|
||||
private List<string> _audioTrackIds;
|
||||
public int AudioTrackCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1; //TODO: Fix
|
||||
if (_audioTrackIds == null)
|
||||
{
|
||||
_audioTrackIds = new List<string>();
|
||||
int mpvFormatString = 1;
|
||||
IntPtr lpBuffer = Marshal.AllocHGlobal(1024);
|
||||
_mpvGetPropertyString(_mpvHandle, Encoding.UTF8.GetBytes("track-list\0"), mpvFormatString, ref lpBuffer);
|
||||
string trackListJson = Marshal.PtrToStringAnsi(lpBuffer);
|
||||
foreach (var json in Json.ReadObjectArray(trackListJson))
|
||||
{
|
||||
string trackType = Json.ReadTag(json, "type");
|
||||
string id = Json.ReadTag(json, "id");
|
||||
if (trackType == "audio")
|
||||
{
|
||||
_audioTrackIds.Add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _audioTrackIds.Count;
|
||||
}
|
||||
}
|
||||
|
||||
private int _audioTrackNumber = 0;
|
||||
public int AudioTrackNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
return _audioTrackNumber;
|
||||
int mpvFormatString = 1;
|
||||
IntPtr lpBuffer = Marshal.AllocHGlobal(10);
|
||||
_mpvGetPropertyString(_mpvHandle, Encoding.UTF8.GetBytes("aid\0"), mpvFormatString, ref lpBuffer);
|
||||
string str = Marshal.PtrToStringAnsi(lpBuffer);
|
||||
if (AudioTrackCount > 1 && _audioTrackIds.Contains(str))
|
||||
{
|
||||
return _audioTrackIds.IndexOf(str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
set
|
||||
{
|
||||
//TODO: Fix
|
||||
//_mpvCommand(_mpvHandle, new[] { "set", "aid", value.ToString(CultureInfo.InvariantCulture), null });
|
||||
//_audioTrackNumber = value;
|
||||
string id = "1";
|
||||
if (AudioTrackCount > 1 && value >= 0 && value < _audioTrackIds.Count)
|
||||
{
|
||||
id = _audioTrackIds[value];
|
||||
}
|
||||
_mpvCommand(_mpvHandle, new[] { "set", "aid", id.ToString(CultureInfo.InvariantCulture), null });
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user