zvonicek / ImageSlideshow

Swift image slideshow with circular scrolling, timer and full screen viewer
MIT License
1.77k stars 475 forks source link

Video Support #406

Open pm-dev opened 3 years ago

pm-dev commented 3 years ago

This is the best open source library for an image carousel I've seen. Nice work! It doesn't however have support for videos. I created a fork which adds support for videos. https://github.com/pm-dev/MediaSlideshow

Wanted to let you know in case you were interested in bringing it into this repo. It took a little bit of refactoring to the 'Core' repo (including renaming "ImageSlideshow" to "MediaSlideshow", then I added an "AV" sub-library to add AVFoundation support. It's not super customizable at the moment because I built it for my use case but works nicely.

primeviltom commented 2 years ago

Edit: Solution found, see down the bottom. I'll leave this comment here in case anyone else experiences a similar issue.

Hey pm-dev, 

I was using ImageSlideshow, and I'm implementing videos into my app now, so I've decided to give your MediaSlideshow fork a go in my project. I've spent the last few hours trying to get it to work, but the documentation appears out of date, and the example project uses slideshow.setMediaSource, which is private in the current version, doesn't appear to work if I set it to public. I might be doing something simple wrong, but I get the following error when I attempt to construct a 'ImageAndVideoSlideshowDataSource' from an AVSource:

let videoSource = AVSource(
                url: URL(string: "https://my-movie-url.mp4")!,
                autoplay: true)

let dataSource = ImageAndVideoSlideshowDataSource(sources: [videoSource])

Error: Cannot convert value of type 'AVSource' to expected element type 'Array<ImageAndVideoSlideshowDataSource.Source>.ArrayLiteralElement' (aka 'ImageAndVideoSlideshowDataSource.Source')

I've included MediaSlideshow and MediaSlideshow/AV in my Podfile, and have imported MediaSlideshow to my swift file. Creating a dataSource with ImageMediaSlideshowDataSource works fine with images, but I need to get video content in there too (using ImageAndVideoSlideshowDataSource). I've tried all types of casting and coercion, all unsuccessfully.  Any help would be hugely appreciated for anyone who uses MediaSlideshow!

Many thanks,

-Tom

EDIT: Found the solution! Download the source code for up to date example code. The dataSource should look like:

lazy var dataSource = ImageAndVideoSlideshowDataSource(
        sources: [.av(videoSource)] + localSource.map { .image($0) },
        onAVAppear: .paused)
pm-dev commented 2 years ago

@primeviltom glad you found the fix. ImageAndVideoSlideshowDataSource.Source is an enum that needs to wrap the video or image source:

    public enum Source {
        case image(ImageSource)
        case av(AVSource)
    }

I've updated the README

davidhsu1115 commented 2 years ago

Update: I have managed to solve it by using SPM to install it. Is there any way to loop video in MediaSlideShow? or go to next page when video end? Thanks.

@pm-dev does your fork library still being maintained? I add pod 'MediaSlideshow', '~> 2.1.1' to my podfile but error message came out: cocoapod could not find compatible version for it.

Noah-Ksk commented 7 months ago

I'm using mediaslideshow and ı prefer to create a mixed slideshow contains videos and images. So ı tried this one but ı got this error message. how could i use it for a video array + image array?

`var kingFisherSources : [KingfisherSource] = [] var videoSource : [AVSource] = []

lazy var dataSource: ImageAndVideoSlideshowDataSource = {
    let avSources = videoSource.map { ImageAndVideoSlideshowDataSource.Source.av($0) }
    let imageSources = kingFisherSources.map { ImageAndVideoSlideshowDataSource.Source.image($0) }

    return ImageAndVideoSlideshowDataSource(sources: avSources + imageSources, onAVAppear: .paused)
}()

for mediaItem in mediaArray { if let mediaUrl = mediaItem["url"] as? String { print("denemeUrl : (mediaUrl)") let mediaType = mediaItem["mediaType"] as? String if mediaType == "image" { let imageKSource = KingfisherSource(urlString: mediaUrl) self.kingFisherSources.append(imageKSource!) } else { let avSource = AVSource(url: URL(string: mediaUrl)!) self.videoSource.append(avSource) `