iOS/macOS media picker for importing images and videos in SwiftUI

Overview

SwiftUI Media Picker

iOS/macOS media picker for importing images and videos in SwiftUI.

Example

import SwiftUI
import AVKit
import MediaPicker

struct ContentView: View {
    @State var urls: [URL] = []
    @State var isShowingMediaPicker = false
    
    var selectButton: some View {
        Button("Select Media") {
            isShowingMediaPicker = true
        }
        .mediaImporter(isPresented: $isShowingMediaPicker,
                       allowedMediaTypes: .all,
                       allowsMultipleSelection: true) { result in
            switch result {
            case .success(let urls):
                self.urls = urls
            case .failure(let error):
                print(error)
                self.urls = []
            }
        }
    }
    
    var body: some View {
        List {
            Section {
                ForEach(urls, id: \.absoluteString) { url in
                    switch try! url.resourceValues(forKeys: [.contentTypeKey]).contentType! {
                    case let contentType where contentType.conforms(to: .image):
                        AsyncImage(url: url) { image in
                            image
                                .resizable()
                                .scaledToFit()
                        } placeholder: {
                            ProgressView()
                        }
                    case let contentType where contentType.conforms(to: .audiovisualContent):
                        VideoPlayer(player: AVPlayer(url: url))
                            .scaledToFit()
                    default:
                        Text("Can't display \(url.lastPathComponent)")
                    }
                }
            } header: {
                selectButton
            }
        }
    }
}
You might also like...
An iOS picker view to serve all your
An iOS picker view to serve all your "picking" needs

Mandoline The PickerView is a UICollectionView that provides a smooth "picking" interface. In order to get the most out of it, a consuming view contro

A country picker view controller for iOS
A country picker view controller for iOS

Planet A country picker view controller for iOS. Installation CocoaPods You can use CocoaPods to install Planet by adding it to your Podfile: platform

MICountryPicker is a country picker controller for iOS8+ with an option to search.
MICountryPicker is a country picker controller for iOS8+ with an option to search.

MICountryPicker MICountryPicker is a country picker controller for iOS8+ with an option to search. The list of countries is based on the ISO 3166 coun

A simple, customizable Country picker for picking country or dialing code. ๐Ÿ‡ฎ๐Ÿ‡ณ ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ฐ๐Ÿ‡ท ๐Ÿ‡ฉ๐Ÿ‡ช ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡บ๐Ÿ‡ธ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ‡ท๐Ÿ‡บ ๐Ÿ‡ฌ๐Ÿ‡ง
A drop in single image picker.

PHSingleImagePicker A low memory, single image picker wrapper that provide a significant smaller file size while also preserve high image quality. Int

React-native-place-picker: Pick any place with single click ๐Ÿš€
React-native-place-picker: Pick any place with single click ๐Ÿš€

React-native-place-picker: Pick any place with single click ๐Ÿš€

 ๐Ÿคฏ PickEmoji: A SwiftUI Extension to Pick the Emojis that you wish
๐Ÿคฏ PickEmoji: A SwiftUI Extension to Pick the Emojis that you wish

๐Ÿคฏ PickEmoji: A SwiftUI Extension to Pick the Emojis that you wish You can use this library in your projects ๐Ÿ™ƒ . You can search the emojis too. Below

A ฮผlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and emoji.

CountryKit CountryKit A ฮผlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and e

Countries - The application lists countries parsed from GeoDB Cities API and lets the user see the details of countries
Countries - The application lists countries parsed from GeoDB Cities API and lets the user see the details of countries

Countries The application lists countries parsed from GeoDB Cities API and lets

Comments
  • The minimal deployment target is lower than the feature used

    The minimal deployment target is lower than the feature used

    /SwiftUI-MediaPicker/Sources/MediaPicker/MediaPicker-iOS.swift:233:72: error: concurrency is only available in iOS 15.0.0 or newer
            private func imageURLs(from phPickerResults: [PHPickerResult]) async throws -> [URL] {
    

    But this package claim to support iOS 14

    opened by hanyang-tony 1
  • Additional PhotosKit filters

    Additional PhotosKit filters

    https://github.com/UWAppDev/SwiftUI-MediaPicker/commit/0e9342d80e944aa16768671b809186b9532ebe20#commitcomment-87290695

    https://stackoverflow.com/questions/70503210/is-it-possible-to-limit-the-video-duration-when-selecting-a-video-using-phpicke

    opened by ApolloZhu 0
Releases(0.2.0)
Owner
Mobile Development Club
RSO at University of Washington, work @UWDevApp
Mobile Development Club
A better SwiftUI Picker Use _Picker instead of Picker

BetterPicker A better SwiftUI Picker. Use _Picker instead of Picker. Create styles with _PickerStyle. The is a WIP This library is currently a work-in

Eric Lewis 17 Dec 14, 2022
Multi-picker for iOS and Mac available in SwiftUI

Multi-picker for iOS and Mac available in Swift UI

1amageek 5 Jul 12, 2022
A SwiftUI implementation of a picker that also allows direct input.

ComboPicker ComboPicker is a SwiftUI view that allows users to input a value by selecting from a predefined set or by typing a custom one. Installatio

Alessio Moiso 5 Sep 13, 2022
FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

null 10 Dec 11, 2022
Elegant and Easy-to-Use iOS Swift Date Picker

D2PDatePicker Example To run the example project, clone the repo, and run pod install from the Example directory first. Example Code: Programmatical I

Pradheep Rajendirane 292 Nov 6, 2022
๐ŸŽฏ Swift country and phone code Picker

CountryPicker Picker code Swift 3 / 4 / 5. Example To run the example project, clone the repo, and run pod install from the Example directory first. U

null 207 Dec 22, 2022
A simple yet customizable horizontal and vertical picker view

WheelPicker A simple yet customizable horizontal and vertical picker view Features Vertical or Horizontal picker Image or Text data Configure UILabel

Mind Studios 74 Sep 26, 2022
LocationPicker - A ready for use and fully customizable location picker for your app

LocationPicker A ready for use and fully customizable location picker for your app. Features Installation Cocoapods Carthage Swift Package Manager Qui

Zhuoran 397 Nov 16, 2022
Date picker dialog for iOS

DatePickerDialog 4.0 - iOS - Swift DatePickerDialog is an iOS drop-in classe that displays an UIDatePicker within an UIAlertView. Requirements DatePic

Squimer 535 Dec 17, 2022
a picker view shown as a popup for iOS in Objective-C

CZPicker Demo Change Log 3 most recent changes are listed here. Full change logs v0.4.3 - 2016-08-12 Added - (void)czpickerViewWillDisplay:(CZPickerVi

Chen Zeyu 527 Oct 2, 2022