开发者

Windows phone 7 Media Element wav pause

开发者 https://www.devze.com 2023-01-31 12:18 出处:网络
I\'m recording sound from microphone. Then I save PCM with wav header to isolated storage. Afterwards I play it using MediaElement. I want to have ability to pause the song but it\'s seems to be impos

I'm recording sound from microphone. Then I save PCM with wav header to isolated storage. Afterwards I play it using MediaElement. I want to have ability to pause the song but it's seems to be impossible. I've tried to use SmoothStreamingMediaElement but the problem was the same - maybe I did something wrong.

If anybody has any idea how to pause the song from microhone then please help.

Here is my code but pause doesn't work. Maybe I can read the file different way?

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var audio = store.OpenFile(_song_path, FileMode.Open, FileAccess.Read))
                {
                    _media_element.MediaOpened += new RoutedEventHandler(_media_element_MediaOpened);
                    _media_element.SetSource(audio);
                    audio.Close();
                }
            }

Pausing code is quite simple :)

private void button2_Click(object sender, RoutedEventArgs e)
    {
        _media_element.Pause();
    }

For testing I have made simple project with ability to downloading files from web and playing it from isolated storage. It works with wmv and mp3 but not with wav. Here is VS project DowloadingAndPlayingWav

If anybody has any idea pleas help. I've hacked probably entire intern开发者_开发知识库et - there is no solution for this problem.


MediaElement has a Pause method. Have you tried using that?


For anyone still interested in this topic (from a search perhaps) I thought I'd share how I handled this in my app (Rapid Recorder).

I couldn't find a proper way to pause but it can easily be faked. When the pause button is clicked you just store the current playback position and you stop the playback. When the play button is pressed you just you can then just set your position again after you start playback. Here are some snippets:

private TimeSpan _pausedPosition;

To pause:

_pausedPosition = Player.Position;
Player.Stop();

To play:

Player.Play();
if (_pausedPosition != TimeSpan.Zero) Player.Position = _pausedPosition;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号