B4A Library B4AGifViewer

Here is a library which lets you show and play gif-animations in your apps.
This library is using android.graphics.Movie.

It is implemented as a CustomView which you add in the B4A designer.
You can also pause and resume the playback of the gif-animation as if it was a mediaplayer. This might be useful for some of you.

If you need to create gif-animations on your device, you could use my B4A ffmpegencoder library.

It is very simple to use. Here below is some sample-code.

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4AGifViewer
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private GifPlayer1 As GifPlayer
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    GifPlayer1.SetGifPath("/storage/sdcard/gif4.gif")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

B4AGifViewer
Version:
1
  • GifPlayer
    Fields:
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • IsPaused As Boolean
    • IsPlaying As Boolean
    • Pause
    • Play
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetGifPath (path As String)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

Please remember that creating libraries and maintaining them takes time and so does supporting them. Please consider a donation if you use my free libraries as this will surely help keeping me motivated. Thank you!
 

Attachments

  • B4AGifViewerLib.zip
    5.8 KB · Views: 386
Last edited:

so27

Active Member
Licensed User
Longtime User
What is the absolute path to Dir.Assets?

The code so does not work!

B4X:
GifPlayer1.SetGifPath(File.DirAssets, "Anleitung.gif")
 

DonManfred

Expert
Licensed User
Longtime User
Should´nt the file in assets lowercased?
 

moster67

Expert
Licensed User
Longtime User
Unsure if it is possible without me changing something in the lib.
You can copy the file to somewhere else, something like this:

B4X:
If File.Exists(File.DirAssets, "Anleitung.gif") Then
        File.Copy(File.DirAssets, "Anleitung.gif",File.DirInternal,"Anleitung.gif")
    Else
        Log("Couldn't find a file. ")
        'do something
End If
 

so27

Active Member
Licensed User
Longtime User
Should´nt the file in assets lowercased?
You're right!

Unsure if it is possible without me changing something in the lib.
You can copy the file to somewhere else, something like this:

B4X:
If File.Exists(File.DirAssets, "Anleitung.gif") Then
        File.Copy(File.DirAssets, "Anleitung.gif",File.DirInternal,"Anleitung.gif")
    Else
        Log("Couldn't find a file. ")
        'do something
End If

Okay thanks!
 

moster67

Expert
Licensed User
Longtime User
@ilan
You can contact me by PM for the ffmpegencoder library
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Here is a library which lets you show and play gif-animations in your apps.
This library is using android.graphics.Movie.

It is implemented as a CustomView which you add in the B4A designer.
You can also pause and resume the playback of the gif-animation as if it was a mediaplayer. This might be useful for some of you.

If you need to create gif-animations on your device, you could use my B4A ffmpegencoder library.

It is very simple to use. Here below is some sample-code.

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4AGifViewer
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private GifPlayer1 As GifPlayer
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    GifPlayer1.SetGifPath("/storage/sdcard/gif4.gif")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

B4AGifViewer
Version:
1
  • GifPlayer
    Fields:
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • IsPaused As Boolean
    • IsPlaying As Boolean
    • Pause
    • Play
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetGifPath (path As String)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

Please remember that creating libraries and maintaining them takes time and so does supporting them. Please consider a donation if you use my free libraries as this will surely help keeping me motivated. Thank you!
Hello,

I'm trying to add a GifViewer dynamically in panels inside a ListView but the gif is not populated after SetGifPath or .Play . Is there any issue to use this object inside a list created dynamically?

#Update: getting an error: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.tillekesoft.b4agifview.GifView.setGifPath(java.lang.String)' on a null object reference
 
Last edited:

moster67

Expert
Licensed User
Longtime User
This is a customview and should be set in the designer. Maybe this is the reason? I don't have much experience with customviews.
I believe it could be done dynamically (I believe Erel posted something about it some time ago) but that would probably require me to do some modifications to the library.
In this moment I am far too busy with other projects but remind me in a week or two and I will see if I can do something...

Edit: or it depends on the way you've written the path...
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
This is a customview and should be set in the designer. Maybe this is the reason? I don't have much experience with customviews.
I believe it could be done dynamically (I believe Erel posted something about it some time ago) but that would probably require me to do some modifications to the library.
In this moment I am far too busy with other projects but remind me in a week or two and I will see if I can do something...

Edit: or it depends on the way you've written the path...
Thanks my friend! I'm adding in design but as it's loaded in many panels while creating the listview it's needed to reference with .getview(x) in order to populate & receive events - it's when I get the problem...
I'm using this library to develop a job and so, if you have some time, will be a pleasure to make a donation/pay for you to find and fix the problem...

Thanks!
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
This is a customview and should be set in the designer. Maybe this is the reason? I don't have much experience with customviews.
I believe it could be done dynamically (I believe Erel posted something about it some time ago) but that would probably require me to do some modifications to the library.
In this moment I am far too busy with other projects but remind me in a week or two and I will see if I can do something...

Edit: or it depends on the way you've written the path...
I'll do a test and take the same Path and show the gifviewer on the parent activity (outside the list panel)... then, I'll post the result here...

UPDATE - tested:

I added a GifPlayer in a Layout and called it directly in Activity_Create - to test, I fixed the path...
GifPlayer1.SetGifPath("/storage/emulated/0/Android/data/com.comten/files/BB2071692B892610D3222E9044384C2775706903C851BFD05BCC8062AFC3F9A1/648EA0CC9742659032BF5DB116C0FB721E5BC8D1095331B1852F3ED7F571ECD5.gif")

Worked!

Then, I added a listview in a layout and loaded the layout in a panel inside a ULV (Ultimate List View) ... In the call back routine to fill the panel, I did:

Dim GifPlayer2 as GifPlayer = LayoutPanel.getview(4)

Then got the error when running:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.tillekesoft.b4agifview.GifView.setGifPath(java.lang.String)' on a null object reference

Which means that it's something related to load a customview inside a panel.

Could u help?
 
Last edited:
Top