B4A Library [B4X][XUI] xImageSliderIG - Instagram style image and video slider

This Instagram style image and video slider is compatible with B4A and B4I.

xImageSliderIG
Author:
@Biswajit
Version: 2.02
Dependency:
  1. B4A: JavaObject, XUI, GestureDetector, AHViewPager(ver. 3), OkHttpUtils2, ExoPlayer
  2. B4I: iXUI, iHttpUtils2, iUI8
Features:
  1. Instagram like Image Counter
  2. Instagram like Dot Indicator
  3. Instagram like Pinch Zoom (only for image item)
  4. Cover blank space with blurry image/color
  5. Customizable Indicator color and animation duration
  6. Single Tap and Double Tap
  7. Fit / Fill / Stretch Image
  8. Lazy loading for both image and video
  9. Loading indicator
  10. Support both local and remote items
  11. Retry loading option for failed remote image
  12. Update item list on runtime
  13. Support video playback both local and remote (uri/dash/hls/smoothstream) (NEW)
  14. Auto-pause while going offscreen (NEW)
  15. Auto-resume while visible 85% (NEW)
  16. Autoplay and start muted video (NEW)
  17. Hide/Show (inside/outside) dot indicators (NEW)
  18. Support video scaling (Fill / Fit / Stretch) (NEW)
Method:
  • SetItems(imgs As List)
    Set/Update items as a list to the slider along with the value as a map you want to receive on tap events
    Image item map format:
    data: your data that will be returned on tap
    image: bitmap / url
    Video item map format:
    data: your data that will be returned on double tap
    video: url / path (combined)
    type: file/uri/dash/hls/smoothstream
  • SetZoomPanel(ZoomPanelContainer As B4XView)
    Set zoom panel (Usually Activity / Root panel) to enable the pinch zoom feature
  • ShowNext
    Show the next item
  • ShowPrev
    Show the previous item
  • PauseCurrentVideo
    Pause the current video item
  • PlayCurrentVideo
    Play the current video item
  • ToggleMute
    Toggle mute of the current video item
  • UpdatePlayback
    Update the current playback state
    Required to pause the playback on activity_pause / page_disappear
    And to resume the playback on activity_resume / page_appear
Property:
  • ActivityHasActionBar As Boolean
    Set it to true if the activity/page has an Action bar (b4a) / Navigation bar (B4I). Default is False. Only needed if the pinch zoom is enabled.
  • CurrentIndex As Int
Designer Property:
  • Show Indicator Dots: Show indicator dots. (OUTSIDE / INSIDE / HIDE) (Default: OUTSIDE)
  • Dots Color: Change the inactive dot indicator color. (Default: #CCCCCC)
  • Active Dot Color: Change the active dot color. (Default: #4286F4)
  • Scale Content: Slider item scale type. (FIT / FILL / STRETCH) (Default: FIT)
  • Cover Free Space: Show a blurry image around the slide image if there is any free space. Only applicable for image item and if FIT scale type is selected. (Default: TRUE)
  • Free Space Color: Show a solid color around the slide item if there is any free space. Only applicable if Cover Free Space is unchecked for image items. (Default: #F4F4F4)
  • Item Count: Show slide count label (Eg. 5/10) (Default: TRUE)
  • Dot Transition Duration: Dots transition time in milliseconds. (Default: 500)
  • Zoom Actual View: If checked the slide will be hidden while zooming (Like Instagram).
  • Autoplay Video: If checked the video will be autoplayed on loading completion. (Default: TRUE)
  • Start Video Muted: If checked the video will start muted on loading completion. (Default: TRUE)
Events:
  • PageChanged(CurrentIndex As Int)
  • VideoPlaying(CurrentIndex As Int)
  • VideoPaused(CurrentIndex As Int)
  • SingleTap(CurrentIndex As Int, Data As Object)
    NOTE: Only for image items. For video items single tap will toggle the video playback state.
  • DoubleTap(CurrentIndex As Int, Data As Object)

Usage:
  1. Add this view from the Designer.
  2. Copy the attached ximageslider_video layout file to your project if you want to show video items.
  3. Create a list having each item as a map. The map will contain a bitmap or URL and data (any object) (See Example). (For Image item)
  4. Create a list having each item as a map. The map will contain a video URL or Path, video type, and data (any object) (See Example). (For Video item)
  5. Set that list to the image slider.
  6. Set zoom panel (optional)
  7. On activity pause / page disappear event pause the current video playback (See Example)
  8. On activity resume / page appear event update the current video playback (See Example)
  9. If you are using multiple sliders in a clv, then call UpdatePlayback on ScrollChange event.
For multiple sliders with CLV check the attached examples.

Update 1.1:

  1. Added support for lazy loading
  2. Added support for remote image loading (Example attached)
  3. New loading indicator and tap to retry option for failed remote image
Update 1.20:
  1. Fixed crash issue in Android 28.
  2. Added support for updating the image list (Check updated example).
Update 1.21: Added new PageChanged event.
Update 1.22: Fixed a crashing issue while using as a single slider with no ActionBar.
Update 2.00:
  1. Fix item scaling issue
  2. Support video playback both local and remote (uri/dash/hls/smoothstream)
  3. Auto-pause while going offscreen
  4. Auto-resume while visible 85%
  5. Autoplay and start muted video
  6. Hide/Show (inside/outside) dot indicators
  7. Support image and video scaling (Fill / Fit / Stretch)
  8. Added new events VideoPlaying and VideoPaused
  9. Changed SetImages method name to SetItems
  10. More accurate blurry cover image.
  11. Now it depends upon ExoPlayer for B4A and iUI8 for B4i
Update 2.01:
  1. Fixed an issue of ShowNext function (B4A)
  2. Fixed double tap issue (B4i)
Update 2.02: Fixed a crashing issue with a slow network connection while playing video.
 

Attachments

  • ximageslider_video_layout.zip
    2.3 KB · Views: 1,252
  • xImageSliderIG_sample_b4a.zip
    169.6 KB · Views: 1,528
  • xImageSliderIG_sample_b4i.zip
    221.4 KB · Views: 1,247
  • xImageSliderIG.b4xlib
    9 KB · Views: 1,081
Last edited:

Biswajit

Active Member
Licensed User
Longtime User
Is there any way to change slides with time.like slideshow? I've used timer and xImageSliderIG1.ShowNext but its not working properly.
No. Actually it also support video playback thats why I didn't added that functionality. Autoslider with video items will not work as expected.

It should work with a timer if you use only image items. What issue are you facing?
 
I'm new to programming.
I've used below code,

B4X:
Dim timerX As Timer
timerX.Initialize("Timer1", 5000)
timerX.Enabled = True

Sub Timer1_Tick
xImageSliderIG1.ShowNext
End Sub

suppose I have 4 images, and when the application started image will shifted from 1st image to 4th image skipping image 2 and 3. And is there any way to start again from the beginning?
 

alimanam3386

Active Member
Licensed User
Longtime User
How we can resize the dot of indicator ?



355.jpg
 

Biswajit

Active Member
Licensed User
Longtime User
For now, there is no option. I think changing the dot size will brake the dot animations (hiding/showing extra dots). Though I will give a try.
 
Last edited:
For now, there is no option. I think changing the dot size will cause the dot animations (hiding/showing extra dots). Though I will give a try.

Can you please tell me how to change the images with timer?
I'm new to programming.
I've used below code,

B4X:

Dim timerX As Timer
timerX.Initialize("Timer1", 5000)
timerX.Enabled = True

Sub Timer1_Tick
xImageSliderIG1.ShowNext
End Sub
suppose I have 4 images, and when the application started image will shifted from 1st image to 4th image skipping image 2 and 3. And is there any way to start again from the beginning?
 

Biswajit

Active Member
Licensed User
Longtime User
suppose I have 4 images, and when the application started image will shifted from 1st image to 4th image skipping image 2 and 3.
I have tested your code. Its working fine. Its showing one by one not skipping as you said.
And is there any way to start again from the beginning?
Check if CurrentIndex = 3 set CurrentIndex = -1 before calling ShowNext.

Update:
Its working fine in ios the android version has some issue. I will post an update today. Thank you for pointing it out.
 
Last edited:

Biswajit

Active Member
Licensed User
Longtime User
Can you please tell me how to change the images with timer?
I'm new to programming.
I've used below code,

B4X:

Dim timerX As Timer
timerX.Initialize("Timer1", 5000)
timerX.Enabled = True

Sub Timer1_Tick
xImageSliderIG1.ShowNext
End Sub
suppose I have 4 images, and when the application started image will shifted from 1st image to 4th image skipping image 2 and 3. And is there any way to start again from the beginning?
Download the new library. And check this example.
 

Attachments

  • ximagesliderig_autoplay_example.zip
    122.6 KB · Views: 776

Sofian

Member
hi..I has try sample code and it works. my problem is when it pinch to zoom img sample #2 show picture as zoom in activity..when timer repeat show next to that img.. it show blank, I tick to that empty img then it show that img #2 pict. It happen to all image that I pinch to zoom. I only change your code to download image from URL and add
pinch:
xImageSliderIG1.SetZoomPanel(Activity)
before
B4X:
timer.Enabled=True
 

Angel Garcia

Member
Licensed User
Hello!,
Nice work!!,
I'm willing to use this library instead of the XUI ImageSlider but, I have a performance question.
When you set URL images on the slider and you swipe back or forward it looks like it downloads the image every time, even the ones that has already passed, am i right??, thats how it works??,
If so a difference with the XUI ImageSlider would be that it has the cached images feature, so that makes sure it wont download the same image more than once.
Please let me know,
Again, great work!
Regards,
 

Biswajit

Active Member
Licensed User
Longtime User
Hello!,
Nice work!!,
I'm willing to use this library instead of the XUI ImageSlider but, I have a performance question.
When you set URL images on the slider and you swipe back or forward it looks like it downloads the image every time, even the ones that has already passed, am i right??, thats how it works??,
If so a difference with the XUI ImageSlider would be that it has the cached images feature, so that makes sure it wont download the same image more than once.
Please let me know,
Again, great work!
Regards,
No. It will download once and use that downloaded image untill you close the Activity or Destroy the view.
 

asales

Expert
Licensed User
Longtime User
Very, very nice.

Two questions:
1 - Can I translate the text: "Couldn't load the video. Tap to retry." ?
2 - Can I set the mute or sound to a specific video in runtime?
 

Biswajit

Active Member
Licensed User
Longtime User
Very, very nice.

Two questions:
1 - Can I translate the text: "Couldn't load the video. Tap to retry." ?
2 - Can I set the mute or sound to a specific video in runtime?
1. Open the b4xlib and change the text as you want.
2. No its not possible right now
 
Top