1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-11 11:34:07 +02:00

Add video player volume sync with user config

This commit is contained in:
chylex 2017-08-11 20:58:37 +02:00
parent 76f2b1a454
commit 308926a2ae
8 changed files with 66 additions and 22 deletions

View File

@ -61,6 +61,7 @@ static UserConfig(){
public bool SwitchAccountSelectors { get; set; } = true;
public bool BestImageQuality { get; set; } = true;
public bool EnableSpellCheck { get; set; } = false;
public int VideoPlayerVolume { get; set; } = 50;
private int _zoomLevel = 100;
private bool _muteNotifications;

View File

@ -394,6 +394,16 @@ protected override void WndProc(ref Message m){
BrowserProcesses.Link(m.LParam.ToInt32(), processId);
}
return;
}
else if (m.Msg == Program.VideoPlayerMessage){
int volume = m.WParam.ToInt32();
if (Handle == m.LParam && volume != Config.VideoPlayerVolume){
Config.VideoPlayerVolume = volume;
Config.Save();
}
return;
}
}

View File

@ -35,7 +35,7 @@ public void Launch(string url){
try{
if ((currentProcess = Process.Start(new ProcessStartInfo{
FileName = PlayerExe,
Arguments = $"{owner.Handle} \"{url}\"",
Arguments = $"{owner.Handle} {Program.UserConfig.VideoPlayerVolume} \"{url}\"",
UseShellExecute = false,
RedirectStandardOutput = true
})) != null){

View File

@ -46,6 +46,7 @@ static class Program{
public static uint WindowRestoreMessage;
public static uint SubProcessMessage;
public static uint VideoPlayerMessage;
private static readonly LockManager LockManager = new LockManager(Path.Combine(StoragePath, ".lock"));
private static bool HasCleanedUp;
@ -73,6 +74,7 @@ private static void Main(){
WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore");
SubProcessMessage = NativeMethods.RegisterWindowMessage("TweetDuckSubProcess");
VideoPlayerMessage = NativeMethods.RegisterWindowMessage("TweetDuckVideoPlayer");
if (!WindowsUtils.CheckFolderWritePermission(StoragePath)){
FormMessage.Warning("Permission Error", "TweetDuck does not have write permissions to the storage folder: "+StoragePath, FormMessage.OK);

View File

@ -24,19 +24,20 @@ protected override void Dispose(bool disposing) {
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.timer = new System.Windows.Forms.Timer(this.components);
this.timerSync = new System.Windows.Forms.Timer(this.components);
this.trackBarVolume = new System.Windows.Forms.TrackBar();
this.tablePanel = new System.Windows.Forms.TableLayoutPanel();
this.progressSeek = new TweetDuck.Video.FlatProgressBar();
this.labelTime = new System.Windows.Forms.Label();
this.timerData = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.trackBarVolume)).BeginInit();
this.tablePanel.SuspendLayout();
this.SuspendLayout();
//
// timer
// timerSync
//
this.timer.Interval = 10;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
this.timerSync.Interval = 10;
this.timerSync.Tick += new System.EventHandler(this.timerSync_Tick);
//
// trackBarVolume
//
@ -52,6 +53,7 @@ private void InitializeComponent() {
this.trackBarVolume.TabIndex = 2;
this.trackBarVolume.TickFrequency = 10;
this.trackBarVolume.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBarVolume.Value = 50;
this.trackBarVolume.ValueChanged += new System.EventHandler(this.trackBarVolume_ValueChanged);
this.trackBarVolume.MouseUp += new System.Windows.Forms.MouseEventHandler(this.trackBarVolume_MouseUp);
//
@ -97,6 +99,11 @@ private void InitializeComponent() {
this.labelTime.TabIndex = 1;
this.labelTime.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// timerData
//
this.timerData.Interval = 500;
this.timerData.Tick += new System.EventHandler(this.timerData_Tick);
//
// FormPlayer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -123,11 +130,12 @@ private void InitializeComponent() {
#endregion
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Timer timerSync;
private System.Windows.Forms.TrackBar trackBarVolume;
private System.Windows.Forms.TableLayoutPanel tablePanel;
private FlatProgressBar progressSeek;
private System.Windows.Forms.Label labelTime;
private System.Windows.Forms.Timer timerData;
}
}

View File

@ -12,7 +12,7 @@ partial class FormPlayer : Form{
private readonly ControlWMP player;
private bool isPaused;
public FormPlayer(IntPtr handle, string url){
public FormPlayer(IntPtr handle, int volume, string url){
InitializeComponent();
this.ownerHandle = handle;
@ -32,8 +32,8 @@ public FormPlayer(IntPtr handle, string url){
player.Ocx.MediaChange += player_MediaChange;
player.Ocx.MediaError += player_MediaError;
trackBarVolume.Value = 25; // changes player volume
trackBarVolume.Value = volume; // changes player volume too if non-default
Application.AddMessageFilter(new MessageFilter(this));
}
@ -44,7 +44,19 @@ private void FormPlayer_Load(object sender, EventArgs e){
player.Ocx.URL = videoUrl;
}
private void timer_Tick(object sender, EventArgs e){
private void player_MediaChange(object item){
timerSync.Start();
Cursor.Current = Cursors.Default;
NativeMethods.SetWindowOwner(Handle, ownerHandle);
Marshal.ReleaseComObject(item);
}
private void player_MediaError(object pMediaObject){
Marshal.ReleaseComObject(pMediaObject);
Environment.Exit(Program.CODE_MEDIA_ERROR);
}
private void timerSync_Tick(object sender, EventArgs e){
if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect)){
int width = rect.Right-rect.Left+1;
int height = rect.Bottom-rect.Top+1;
@ -76,16 +88,9 @@ private void timer_Tick(object sender, EventArgs e){
}
}
private void player_MediaChange(object item){
timer.Start();
Cursor.Current = Cursors.Default;
NativeMethods.SetWindowOwner(Handle, ownerHandle);
Marshal.ReleaseComObject(item);
}
private void player_MediaError(object pMediaObject){
Marshal.ReleaseComObject(pMediaObject);
Environment.Exit(Program.CODE_MEDIA_ERROR);
private void timerData_Tick(object sender, EventArgs e){
timerData.Stop();
NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, Program.VideoPlayerMessage, new UIntPtr((uint)trackBarVolume.Value), ownerHandle);
}
private void progressSeek_Click(object sender, EventArgs e){
@ -94,6 +99,11 @@ private void progressSeek_Click(object sender, EventArgs e){
private void trackBarVolume_ValueChanged(object sender, EventArgs e){
player.Ocx.settings.volume = trackBarVolume.Value;
if (timerSync.Enabled){
timerData.Stop();
timerData.Start();
}
}
private void trackBarVolume_MouseUp(object sender, MouseEventArgs e){

View File

@ -3,7 +3,15 @@
namespace TweetDuck.Video{
static class NativeMethods{
public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF);
private const int GWL_HWNDPARENT = -8;
[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern uint RegisterWindowMessage(string messageName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]

View File

@ -10,23 +10,28 @@ static class Program{
public const int CODE_MEDIA_ERROR = 3;
public const int CODE_OWNER_GONE = 4;
private static uint? message;
public static uint VideoPlayerMessage => message ?? (message = NativeMethods.RegisterWindowMessage("TweetDuckVideoPlayer")).Value;
[STAThread]
private static int Main(string[] args){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
IntPtr ownerHandle;
int defaultVolume;
string videoUrl;
try{
ownerHandle = new IntPtr(int.Parse(args[0], NumberStyles.Integer, CultureInfo.InvariantCulture));
videoUrl = new Uri(args[1], UriKind.Absolute).AbsoluteUri;
defaultVolume = int.Parse(args[1], NumberStyles.Integer, CultureInfo.InvariantCulture);
videoUrl = new Uri(args[2], UriKind.Absolute).AbsoluteUri;
}catch{
return CODE_INVALID_ARGS;
}
try{
Application.Run(new FormPlayer(ownerHandle, videoUrl));
Application.Run(new FormPlayer(ownerHandle, defaultVolume, videoUrl));
}catch(Exception e){
// TODO
Console.Out.WriteLine(e.Message);