B4J Question Programmatically set MediaView instance

bdunkleysmith

Active Member
Licensed User
Longtime User
In this piece of code:

B4X:
Private MediaView0, MediaView1,  MediaView2, MediaView3, MediaView4, MediaView5, MediaView6, MediaView7, MediaView8, MediaView9, MediaView10, MediaView11 As MediaView

Sub LoadMediaView   
    For Each k As Object In mapHomeTeam.Keys
        Dim playerId As String = mapHomeTeam.Get(k)
        For a = 0 To mapHomeTeam.Size - 1
            If playerId = arrayHome(a, 0) Then
                If File.Exists(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, mediaFile & ".mp4") = True Then
                    
                    MediaView0.Initialize(Me, "mpp")
                    MediaView0.Source = File.GetUri(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, mediaFile)
                    
                End If
            End If
        Next
    Next
End Sub

I want to to programmatically set the MediaView instance to MediaView0, MediaView1, MediaView2, etc. where the numeric suffix is equal to the variable a.

I am sure I've seen a solution to this in the Forum, but despite extensive searching, I can't find it and so I'd appreciate any guidance.

Incidentally, I assume there's no problem with each instance having the same event name, but please advise if that's not the case.
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks @Erel. I'll investigate SimpleMediaManager to see if it simplifies my implementation or more importantly is more resilient given the random

MediaException: UNKNOWN : [com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer@451e41d6] ERROR_MEDIA_INVALID: ERROR_MEDIA_INVALID

errors I'm chasing. I just don't understand why with code and videos that have worked without error for nearly 2 years, mediaexception errors are now being thrown randomly.

However, my continuing search led me to the previous post I was after which made use of an array of MediaViews. Here's my resultant code:

B4X:
Private introMediaView(12) As MediaView

Sub LoadMediaView  
    Dim vn As Int = 0
    For Each k As Object In mapHomeTeam.Keys
        Dim playerId As String = mapHomeTeam.Get(k)
        For a = 0 To mapHomeTeam.Size - 1
            If playerId = arrayHome(a, 0) Then
                If File.Exists(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, mediaFile & ".mp4") = True Then
                   
                introMediaView(vn).Initialize(Me, "mpp")
                introMediaView(vn).DesignerCreateView(Display.fullPane, Null , Null)
                introMediaView(vn).Source = File.GetUri(PublicApplicationDataFolder & "\Intros\" & cmbOrganisationID.Value, mediaFile & ".mp4")
                introMediaView(vn).mMediaView.Visible = False
                   
                End If
            End If
        Next
    vn = vn + 1
    Next
End Sub
 
Upvote 0
Top