mirror of
https://git.alee14.me/shiftos-archive/ShiftOS_TheReturn.git
synced 2025-01-22 18:02:16 +00:00
audio player scrubbing
This commit is contained in:
parent
99b438dd8f
commit
d22957d2ab
2 changed files with 66 additions and 1 deletions
|
@ -64,6 +64,7 @@ namespace ShiftOS.WinForms.Applications
|
|||
this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.shuffleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.loopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)(this.wpaudio)).BeginInit();
|
||||
this.toolStripContainer1.ContentPanel.SuspendLayout();
|
||||
this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
|
||||
|
@ -150,6 +151,9 @@ namespace ShiftOS.WinForms.Applications
|
|||
this.pgplaytime.Tag = "keepbg";
|
||||
this.pgplaytime.Text = "shiftedProgressBar1";
|
||||
this.pgplaytime.Value = 0;
|
||||
this.pgplaytime.MouseDown += new System.Windows.Forms.MouseEventHandler(this.startScrub);
|
||||
this.pgplaytime.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pgplaytime_MouseMove);
|
||||
this.pgplaytime.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pgplaytime_MouseUp);
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
|
@ -158,7 +162,8 @@ namespace ShiftOS.WinForms.Applications
|
|||
this.addSongToolStripMenuItem,
|
||||
this.clearToolStripMenuItem,
|
||||
this.shuffleToolStripMenuItem,
|
||||
this.removeToolStripMenuItem});
|
||||
this.removeToolStripMenuItem,
|
||||
this.loopToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(798, 24);
|
||||
|
@ -193,6 +198,13 @@ namespace ShiftOS.WinForms.Applications
|
|||
this.removeToolStripMenuItem.Text = "Remove";
|
||||
this.removeToolStripMenuItem.Click += new System.EventHandler(this.removeToolStripMenuItem_Click);
|
||||
//
|
||||
// loopToolStripMenuItem
|
||||
//
|
||||
this.loopToolStripMenuItem.CheckOnClick = true;
|
||||
this.loopToolStripMenuItem.Name = "loopToolStripMenuItem";
|
||||
this.loopToolStripMenuItem.Size = new System.Drawing.Size(46, 20);
|
||||
this.loopToolStripMenuItem.Text = "Loop";
|
||||
//
|
||||
// AudioPlayer
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -229,5 +241,6 @@ namespace ShiftOS.WinForms.Applications
|
|||
private System.Windows.Forms.FlowLayoutPanel flcontrols;
|
||||
private System.Windows.Forms.Button btnplay;
|
||||
private Controls.ShiftedProgressBar pgplaytime;
|
||||
private System.Windows.Forms.ToolStripMenuItem loopToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,6 +160,23 @@ namespace ShiftOS.WinForms.Applications
|
|||
}));
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
if (o.PlaybackState == NAudio.Wave.PlaybackState.Stopped)
|
||||
{
|
||||
if (lbtracks.SelectedIndex < lbtracks.Items.Count - 1)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
lbtracks.SelectedIndex++;
|
||||
}));
|
||||
}
|
||||
else if(loopToolStripMenuItem.Checked == true)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
lbtracks.SelectedIndex = 0;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
|
||||
|
@ -171,6 +188,41 @@ namespace ShiftOS.WinForms.Applications
|
|||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
bool scrubbing = false;
|
||||
|
||||
private void startScrub(object sender, MouseEventArgs e)
|
||||
{
|
||||
scrubbing = true;
|
||||
}
|
||||
|
||||
static public double linear(double x, double x0, double x1, double y0, double y1)
|
||||
{
|
||||
if ((x1 - x0) == 0)
|
||||
{
|
||||
return (y0 + y1) / 2;
|
||||
}
|
||||
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
|
||||
}
|
||||
|
||||
private void pgplaytime_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (mp3 != null)
|
||||
try
|
||||
{
|
||||
if (scrubbing)
|
||||
{
|
||||
long s_pos = (long)linear(e.X, 0, pgplaytime.Width, 0, (double)mp3.Length);
|
||||
mp3.Position = s_pos;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private void pgplaytime_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
scrubbing = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ListExtensions
|
||||
|
|
Loading…
Reference in a new issue