Как показывать видео и изображения с помощью команды Resact-native-image-picker
import ImagePicker from 'react-native-image-picker';
const options = {
title: 'Select Image',
takePhotoButtonTitle:'take a photo',
chooseFromlibraryButtonTitle:'choose from gallery',
quality:1
};
class Upload extends Component <{}>{
static navigationOptions = { header: null }
constructor(){
super()
this.state ={
ImageSource:null
}
}
selectPhoto(){
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else {
let source = { uri: response.uri };
this.setState({
ImageSource: source,
});
}
});
}
- как показывать видео с изображением в режиме native native и с помощью video soucr uri state по-прежнему показывает только изображение 2. и если с помощью mediatypes все еще показывает изображение, как это исправить
3 ответа
Вы разрабатываете для Android/iOS/ Оба? Похоже, вы должны указать mediaType={mixed}
для iOS, и вам нужно будет указать, хотите ли вы увидеть видео или изображения для Android.
Ну вот
ImagePicker.showImagePicker({
title: 'Choose Image or Video',
customButtons: [{ name: 'image', title: 'Take a Photo' },{ name: 'video', title: 'Take a Video' }],
chooseFromLibraryButtonTitle: null,
takePhotoButtonTitle: null,
}, (res) => {
if(res.customButton ){
ImagePicker.launchCamera({
mediaType: res.customButton,
videoQuality: 'high',
quality: 1,
}, (response) => {
// Same code as in above section!
});
}
});
const selectGalleryMedia = async () => {
const options = {
title: "Select Images/Videos",
mediaType: "mixed",
selectionLimit: 0,
storageOptions: {
skipBackup: true,
path: "images",
},
};
launchImageLibrary(options, (res) => {
console.log("Response = ", res);
});
};