#Region "LICENSE"
'
' Copyright (c) Microncode.com
' 
' This source is subject to the Microsoft Public License. 
' See https://opensource.org/licenses/ms-pl.html.
' All other rights reserved. 
' 
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
'
#End Region

Imports CSMediaProperties
Imports System.Diagnostics
Imports System.Linq
Imports System.Windows.Forms

Namespace CSVideoPlayerExampleWinForms
    Public Partial Class frmMediaProperties
        Inherits Form

        ''' <summary>
        ''' Constructor.
        ''' </summary>
        Public Sub New()
            Me.InitializeComponent()
        End Sub


        ''' <summary>
        ''' Get the media details to the PropertyGrid control.
        ''' </summary>
        ''' <paramname="file"></param>
        Public Async Sub GetDetails(ByVal file As String)
            Using videoPlayer = New CSVideoPlayer.VideoPlayerWinForm()
                'Init function, must be call before using any functionality of the component.

                'Set the path of the ffmpeg libraries
                Dim LibsPath As String = ""

                'If the LibsPath is empty or "" the library will search for
                'the ffmpeg libraries under the path:
                '[AssemblyDirectory]\CSPlugins\FFmpeg\[x86|x64]\

                videoPlayer.Init("UserName", "RegKey", LibsPath)

                'Create mediaProperties
                Dim mediaProperties As MediaProperties = New MediaProperties()

                'Get the details
                mediaProperties = Await videoPlayer.GetDeatils(file)


                'Now the mediaProperties contains all the information about the media file.
                'mediaProperties.Format.BitRate
                'mediaProperties.Format.Duration
                ' etc..

                'You can access all the information for each stream in the streams like this:
                For Each stream In mediaProperties.Streams.Stream
                    Debug.WriteLine("stream.Duration index " & stream.Index)
                    Debug.WriteLine(stream.Duration)
                    'etc..
                Next


                'You can access to the id3 tags like this:

                'Check if the media file contains id3 title tag:
                If mediaProperties.Format.Tags.FirstOrDefault(Function(tag) Equals(tag.Key, "title")) IsNot Nothing Then
                    'The id3 title tag existed, print it:
                    Debug.WriteLine("ID3 tag title")
                    Debug.WriteLine(Enumerable.FirstOrDefault(mediaProperties.Format.Tags, Function(tag) Equals(tag.Key, "title")).Value)
                End If


                'Create a property grid for the display (winform component)

                'Set the data to the propertyGrid1
                Me.propertyGrid1.SelectedObject = mediaProperties
                Me.propertyGrid1.ExpandAllGridItems()
            End Using
        End Sub
    End Class
End Namespace
