[C#][VB.NET]使用AxMediaPlayer撥放多媒體
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /white-space: pre;/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }]]>Step6.撰寫停止程式碼這邊需注意的是,AxMediaPlayer控制項的Stop函式雖然會停止撥放,但是停止後撥放位置仍維持在原位,因此當又按下撥放時,該控制項會從上次位置繼續撥放,有點類似暫停的功能(跟暫停的差異在於它會按下控制項上的Stop按鈕),因此這邊須自行把撥放位置設回起始點。VB.NET Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click Me.AxMediaPlayer1.Stop() ‘停止 AxMediaPlayer1.CurrentPosition = 0 ‘把撥放位置設回起點 End Sub C# private void btnStop_Click(object sender, EventArgs e) { this.axMediaPlayer1.Stop(); //停止 this.axMediaPlayer1.CurrentPosition = 0; //把撥放位置設回起點 } Step7.撰寫暫停撥放程式碼撰寫這部份功能程式碼只需呼叫AxMediaPlayer.Pause()即可。VB.NET Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click Me.AxMediaPlayer1.Pause() ‘暫停撥放 End Sub C# private void btnPause_Click(object sender, EventArgs e) { this.axMediaPlayer1.Pause(); //暫停撥放 } Step8.撰寫音量控制程式碼這部份功能程式碼只需對AxMediaPlayer.Volume做屬性值的變更即可。VB.NET Private Sub tbarVolume_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarVolume.Scroll Me.AxMediaPlayer1.Volume = tbarVolume.Value ‘改變音量大小 End Sub Private Sub btnIncreaseVolume_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIncreaseVolume.Click Me.AxMediaPlayer1.Volume += 1 ‘音量大小+1 End Sub Private Sub btnDecreaseVolume_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecreaseVolume.Click Me.AxMediaPlayer1.Volume -= 1 ‘音量大小-1 End Sub C# private void tbarVolume_Scroll(object sender, EventArgs e) { this.axMediaPlayer1.Volume = tbarVolume.Value; //改變音量大小 } private void btnIncreaseVolume_Click(object sender, EventArgs e) { this.axMediaPlayer1.Volume += 1; //音量大小+1 } private void btnDecreaseVolume_Click(object sender, EventArgs e) { this.axMediaPlayer1.Volume -= 1; //音量大小-1 } Step9.撰寫撥放位置控制程式碼這部份功能程式碼只需對AxMediaPlayer.CurrentPosition做屬性值的變更即可。VB.NET Private Sub tbarPlayLoaction_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarPlayLoaction.Scroll Me.AxMediaPlayer1.CurrentPosition = tbarPlayLoaction.Value ‘改變撥放位置 End Sub C# private void tbarPlayLoaction_Scroll(object sender, EventArgs e) { this.axMediaPlayer1.CurrentPosition = tbarPlayLoaction.Value; //改變撥放位置 } Download使用AxMediaPlayer撥放多媒體.zip <![CDATA[
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /white-space: pre;/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }]]><![CDATA[
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, “Courier New”, courier, monospace; background-color: #ffffff; /white-space: pre;/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }]]>參考連結藍色小鋪 - media 播放設定問題如何使用 Visual Basic.NET 或 Visual Basic 2005 中播放音訊檔案