gpt4 book ai didi

c# - 是否可以在 BackgroundAudioPlayer 中设置开始和结束位置

转载 作者:行者123 更新时间:2023-11-30 18:26:21 25 4
gpt4 key购买 nike

我正在四处寻找为 BackgroundAudioPlayer 设置开始和结束位置。虽然我可以设置开始位置,但是我也希望设置结束位置。

假设,我的音频文件是 22 分钟,用户只想听到第 10 分钟到第 18 分钟的声音。是否有可能在 BackgroundAudioPlayer 中设置开始和结束位置?

谢谢!

最佳答案

我在桌面应用程序方面遇到了这个挑战,我通过启动一个计时器并将滴答时间设置为停止-开始位置解决了这个问题。当计时器触发时,您将停止音频播放器和计时器。

您也可以使用线程来完成此操作,但计时器似乎是一种更简洁的解决方案。下面是一个示例 - 尽管我使用了属于 GUI 的 MediaElement(这就是我使用 pinvoke 的原因)。

void sndPlayer_MediaOpened(object sender, EventArgs e)
{
// Set the current position in the recording
sndPlayer.Position = currentRecording.tPosition;

// Start playing
sndPlayer.Play();

// Schedule a function to stop the player
timerControlPlayer.Interval = (double)currentDuration * 1000.0;
timerControlPlayer.Start();
}

void timerControlPlayer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
// We don't need the timer to pop in again
timerControlPlayer.Stop();

// Access the gui thread (the sound player belongs to that one)
guiDispatcher.Invoke(() =>
{
sndPlayer.Stop();
SoundPlayed(this, new SoundPlayedEventArgs(currentRecording.nSpeakerCount));
sndPlayer.Close();
});
}

// Used as an elegant solution to start / stop the sound player
timerControlPlayer = new System.Timers.Timer();
timerControlPlayer.Elapsed += timerControlPlayer_Elapsed;

关于c# - 是否可以在 BackgroundAudioPlayer 中设置开始和结束位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28646659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com