media
import "github.com/tangoui/tango/sys/media"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package media lets the user pick photos and videos from the library or take a photo with the camera.
paths, err := media.Pick(a, media.PickOptions{Limit: 5})
path, err := media.TakePhoto(a)
Pick uses the system picker (PHPickerViewController on iOS, the Android Photo Picker), which runs out of process and needs no photo library permission. TakePhoto uses the system camera UI (UIImagePickerController, ACTION_IMAGE_CAPTURE); iOS needs NSCameraUsageDescription (permission "camera" in tan.json) and returns ErrNotConfigured without it.
The returned paths are copies in the app's cache directory (iOS: Library/Caches/tango-media, Android: cache/tango-media), readable with os.Open; delete them when done. Canceling returns ErrCanceled.
Functions return ErrUnsupported where the backend has no picker or camera (desktop: use package dialog) and tango.ErrNotRunning after the app quit. On Android call them from a goroutine, not from a main-thread callback.
常量
const (
Images = platform.MediaImages
Videos = platform.MediaVideos
)变量
var (
ErrUnsupported = platform.ErrUnsupported
ErrCanceled = platform.ErrCanceled
ErrNotAvailable = platform.ErrNotAvailable
ErrPermissionDenied = platform.ErrPermissionDenied
ErrNotConfigured = platform.ErrNotConfigured
)函数
func Pick
func Pick(a *tango.App, o PickOptions) ([]string, error)Pick shows the photo picker and returns the chosen items' paths in the order picked.
func TakePhoto
func TakePhoto(a *tango.App) (string, error)TakePhoto opens the camera and returns the path of the JPEG taken. ErrNotAvailable means the device has no camera (the iOS simulator).
类型
PickOptions
type PickOptions struct {
Types Type // Images, Videos or both; 0 means Images
Limit int // most items the user may choose; 0 or 1 = one
// contains filtered or unexported fields
}PickOptions configures Pick.
Type
type Type = platform.MediaTypeType selects what Pick offers.