TechSpot

20.6.1 A class for Custom MediaStreamSource

By Ubamae
Jun 25, 2010
  1. HI to all,
    To implement your own custom stream source, derive a class from MediaStreamSource. As the name suggests, this class will be used as the source for a MediaElement on the page. Table 20.10 shows that MediaStreamSource has several methods that you must override in your implementation.

    Table 20.10 MediaStreamSource Virtual Methods

    Method


    Description

    SeekAsync


    Sets the next position to be used in GetSampleAsync. Call ReportSeekCompleted when done.

    GetDiagnosticAsync


    Used to return diagnostic information. This method can be a no-op as it is not critical. If used, call ReportGetDiagnosticCompleted when done.

    SwitchMediaStreamAsync


    Used to change between configured media streams. This method can be a no-op as it is not critical. If used, call ReportSwitchMediaStreamCompleted when done.

    GetSampleAsync


    Required. Get the next sample and return it using ReportGetSampleCompleted. If there is any delay, call ReportGetSampleProgress to indicate buffering.

    OpenMediaAsync


    Required. Set up the metadata for the media and call ReportOpenMediaCompleted.

    CloseMedia


    Any shutdown and cleanup code should go here

    One thing you'll notice about the functions is that many of them are asynchronous. The pattern followed in those methods is to perform the processing and then call a ReportComplete method, the name of which varies by task, when finished.

    The async nature of the API helps keep performance up, and keeps your code from slowing down media playback.

    Listing 20.4 shows the skeleton of a MediaStreamSource implementation, including the methods described above. We'll continue to build on this throughout the remaining raw media sections.
     
Topic Status:
Not open for further replies.

Similar Topics

Add New Comment

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...