1
Vote

fix: work in Silverlight 4 RC and higher ( cspeex-30525 source version works only in SL 4 Beta)

description

1) at "MainPage.xaml.cs", replace with this method implementation:
 
    private void TakeSnapshot_Click(object sender, RoutedEventArgs e)
    {
        if (_captureSource != null)
        {
            // capture the current frame and add it to our observable collection
            _captureSource.CaptureImageCompleted += (source, eventargs) =>
            {
                _images.Add(eventargs.Result);
            }; //Birbilis: using Silverlight 4 RC and higher API, not Silverlight Beta ("ImageCaptureAsync" method has been replaced by "CaptureImageAsync")
            _captureSource.CaptureImageAsync();
        }
    }
 
2) at "StreamAudioSync.cs" do this small change:
 
    protected override void OnFormatChange(AudioFormat audioFormat)
    {
        if (audioFormat.WaveFormat == WaveFormatType.Pcm) //Birbilis: "PCM" has been renamed to "Pcm" in Silverlight 4 RC and higher (was using Silverlight 4 Beta here)
        { 
...

file attachments

comments

Birbilis wrote Jun 9, 2012 at 10:18 AM

.

Birbilis wrote Jun 9, 2012 at 10:19 AM

wrote Jun 9, 2012 at 12:15 PM

Birbilis wrote Jun 9, 2012 at 12:15 PM

in fact, better wrap CaptureImageAsync with try/catch for InvalidOperationException and move the capture event handler initialization to other place so that we don't add more and more event handlers at every button click
  private void TakeSnapshot_Click(object sender, RoutedEventArgs e)
    {
        if (_captureSource != null)
        {
            try
            {
                // capture the current frame and add it to our observable collection
                _captureSource.CaptureImageAsync();
            }
            catch (System.InvalidOperationException ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
    }


    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        // get list of audio sources
        AudioSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices();

        // get list of the video sources
        VideoSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();

        // creating a new capture source
        _captureSource = new CaptureSource();

        // set event handler for image capture
        _captureSource.CaptureImageCompleted += (source, eventargs) =>
        {
            _images.Add(eventargs.Result);
        }; //Birbilis: using Silverlight 4 RC and higher API, not Silverlight Beta ("ImageCaptureAsync" method has been replaced by "CaptureImageAsync")

        streamAudioSink = new StreamAudioSink();

        streamAudioSink.CaptureSource = _captureSource;

        // bind snapshot images
        Snapshots.ItemsSource = _images;
    }
btw, not sure if the sample works ok, I don't see captured image, and when trying to save audio I get null pointer exception at Stream memStream = streamAudioSink.MemFile.InnerStream; in "SaveAudio_Click" method

Birbilis wrote Jun 9, 2012 at 12:16 PM

one of the MainPage.xaml.cs contains the extra fix

ClipFlair wrote Aug 4, 2012 at 4:35 PM

Also note that the CSpeex-SL project won't load if you don't have Silverlight 3 SDK installed. After loading you can open up properties of that project and of SLAudioDemo one and set the target to Silverlight 5 from Silverlight 3, then save those two projects and rebuild the solution

wrote Feb 13, 2013 at 10:35 PM