private void btnRecord_Click(object sender, EventArgs e)
{
FFmpeg_Capture record = new FFmpeg_Capture();
record.Start("Testing", 60);
}
我想要做的是,當我單擊按鈕時,它將其文本更改為“停止”,然后當我再次單擊時,它將執行代碼:
record.Stop();
并將按鈕的文本更改回“記錄”,以便我可以使用相同的按鈕開始/停止。
uj5u.com熱心網友回復:
最簡單的方法可能是引入將存盤當前玩家狀態的標志。對于只是播放/停止,此標志可能是bool,對于更多狀態,例如播放/暫停/停止,它可能是enum。然后您可以使用此標志來確定當前狀態并相應地更改它
bool playing = false;
FFmpeg_Capture record = new FFmpeg_Capture();
private void btnRecord_Click(object sender, EventArgs e)
{
if(playing)
{
record.Stop();
playing = false;
btnRecord.Text = "Play";
}
else
{
record.Start("Testing", 60);
btnRecord.Text = "Stop";
playing = true;
}
}
這里的問題是您可能有其他方法來更改玩家的狀態(例如,通過單擊玩家本身),因此您需要playing在所有此類位置維護標志以與真實玩家狀態同步。
因此,更好的方法是檢查播放器本身的狀態(如果播放器有這樣的 API)。我假設玩家具有State列舉屬性,并且該屬性表示當前狀態。在這種情況下,代碼可能如下。我不知道真正的玩家是否有這樣的屬性,所以這只是一個想法。
FFmpeg_Capture record = new FFmpeg_Capture();
private void btnRecord_Click(object sender, EventArgs e)
{
if(record.State is CaptureState.Playing)
{
record.Stop();
btnRecord.Text = "Play";
}
else
{
record.Start("Testing", 60);
btnRecord.Text = "Stop";
}
}
uj5u.com熱心網友回復:
為當前按鈕狀態添加一個布林值。
if(button_state)
{
FFmpeg_Capture record = new FFmpeg_Capture();
record.Start("Testing", 60);
button_state != button_state;
btnRecord.Text = "Stop";
}
else
{
record.Stop();
btnRecord.Text = "Record"
button_state != button_state;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/495631.html
