Player Events

Playback Events

During playback, the player fires various events to reflect its internal state. You can handle them like this:

void OnPlayerEvent(Player_State ev, string info, long param)
{
    switch (ev)
    {
        case Player_State.Starting:           // Graph is being built
            break;

        case Player_State.WaitingFordata:     // Playback started, waiting for data (timeout)
            break;

        case Player_State.Running:            // Session is running
            break;

        case Player_State.Paused:             // Session is paused
            break;

        case Player_State.Stopped:            // Session is stopped
            break;

        case Player_State.Completed:          // Session completed
            break;

        case Player_State.Error:              // Playback error occurred
            break;

        case Player_State.Demo_Expired:       // Demo period expired
            break;

        case Player_State.DurationChanged:    // Total duration has changed
            break;

        case Player_State.SegmentChanged:     // Current segment has changed
            break;

        case Player_State.SegmentListChanged: // Segment list has changed
            break;

        default:
            break;
    }
}

Error Event

If an error occurs during playback, the player will trigger the ErrorEvent. You can handle it as follows:

void OnErrorEvent(Error_Type e, string err)
{
    ReportError("Error {0} - {1}", e, err);
}

PID Detection

Once the player finishes analyzing the stream, it triggers the PidDetectionEvent, providing a list of detected PIDs (Packet Identifiers). This allows you to inspect which types of data (video, KLV metadata, private data) are present in the stream.

Example:

void OnPidDetectionEvent(List<PidInfoWr> pidList)
{
    pidList.ForEach(pid =>
{   
        switch (pid.streamType)
        {
            case StreamType.VIDEO:
                // Video stream detected
                break;

            case StreamType.KLV:
                // KLV metadata stream detected
                break;

            case StreamType.PRIVATE_DATA:
                // Private data stream detected
                break;
        }   
    });
}

Note: Setting this event handler is optional. It’s only necessary if your application requires awareness of stream components.

Sync Frame Event

After frame decoding is complete, the player triggers the SyncFrameEvent, providing a list of synchronized data packets. These may include uncompressed video frames, KLV metadata, or private data packets.

Example usage:

void OnSyncFrameEvent(List<StreamFrameInfoWr> streamList)
{
    streamList.ForEach(delegate(StreamFrameInfoWr streamFrame)
    {
        switch (streamFrame.streamType)
        {
            case StreamType.VIDEO:
                {
                    // Uncompressed video frame received
                    VideoFrameInfoWr vf = streamFrame as VideoFrameInfoWr;
                }
                break;

            case StreamType.KLV:
                {
                    // KLV metadata packet received
                    KlvFrameInfoWr kf = streamFrame as KlvFrameInfoWr;
                    if (kf.duplicateCounter == 0 && kf.decodedData != null)
                    {
                        // Process KLV data
                    }
                }
                break;

            case StreamType.PRIVATE_DATA:
                {
                    // Private data packet received
                    DataFrameInfoWr df = streamFrame as DataFrameInfoWr;
                    if (df.duplicateCounter == 0)
                    {
                        // Process private data
                    }
                }
                break;
        }
    });
}