123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <template>
- <!-- #ifdef APP -->
- <scroll-view style="flex: 1;">
- <!-- #endif -->
- <view>
- <page-head :title="title"></page-head>
- <!-- #ifdef APP-IOS -->
- <view style="padding-left: 20px; padding-right: 20px;">
- <text style="color: #353535; font-size: 15px;">
- iOS 调试首先需要添加对应 audio、video、image 存储到文件系统中,步骤如下:\n
- 1. 从系统相册或者语音备忘录中选择具体的video、image、audio;\n
- 2. 点击 ‘分享’ 按钮;\n
- 3. 下滑点击 ’存储到”文件“‘按钮;\n
- </text>
- </view>
- <!-- #endif -->
- <button size="mini" @click="log=''">清空日志</button>
- <text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ log }}</text>
- <button class="btnstyle" type="primary" @tap="chooseVideo">选择文件(video) 单选</button>
- <button class="btnstyle" type="primary" @tap="chooseVideoMul">选择文件(video) 多选</button>
- <button class="btnstyle" type="primary" @tap="playVideo">选择文件(video)并播放</button>
- <video class="video" :src="src" :controls="true" :autoplay="true" :loop="true">111</video>
- <button class="btnstyle" type="primary" @tap="chooseImage">选择文件(image) 单选</button>
- <button class="btnstyle" type="primary" @tap="chooseImageMul">选择文件(image) 多选</button>
- <button class="btnstyle" type="primary" @tap="viewImg">选择文件(image) 并预览</button>
- <button class="btnstyle" type="primary" @tap="chooseAudio">选择文件(audio) 单选</button>
- <button class="btnstyle" type="primary" @tap="chooseAudioMul">选择文件(audio) 多选</button>
- <button class="btnstyle" type="primary" @tap="playAudio">选择文件(audio) 并播放</button>
- <button class="btnstyle" type="primary" @tap='chooseAll'>选择文件(all) 单选</button>
- <button class="btnstyle" type="primary" @tap='chooseAllMul'>选择文件(all) 多选</button>
- <view style="height: 4px;"></view>
- </view>
- <!-- #ifdef APP -->
- </scroll-view>
- <!-- #endif -->
- </template>
- <script>
- export default {
- data() {
- return {
- log: '',
- title: 'choose-file',
- src: '',
- _audioContext: null as InnerAudioContext | null,
- }
- },
- unmounted() {
- if (this._audioContext != null) {
- this._audioContext!.destroy()
- }
- },
- methods: {
- getPath(chooseFils : ChooseFileTempFile[]) : string {
- var urls = new Array<string>()
- chooseFils.forEach(value => {
- urls.push(value.path)
- })
- return urls.join(', ')
- },
- chooseVideo() {
- uni.chooseFile({
- type: 'video',
- count: 1,
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- chooseVideoMul() {
- uni.chooseFile({
- type: 'video',
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- playVideo() {
- uni.chooseFile({
- type: 'video',
- count: 1,
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.src = res.tempFiles[0].path
- this._audioContext?.destroy()
- this._audioContext = null
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- chooseImage() {
- uni.chooseFile({
- type: 'image',
- count: 1,
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- chooseImageMul() {
- uni.chooseFile({
- type: 'image',
- count: 90,
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- viewImg() {
- uni.chooseFile({
- type: 'image',
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- const tempFiles: Array<string> = res.tempFiles.map((value) => {
- return value.path
- })
- uni.previewImage({
- current: 0,
- urls: tempFiles,
- success: (res) => {
- console.log(res)
- },
- fail: (err) => {
- console.log(err)
- }
- })
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- chooseAudio() {
- uni.chooseFile({
- type: 'audio',
- count: 1,
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- chooseAudioMul() {
- uni.chooseFile({
- type: 'audio',
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- playAudio() {
- uni.chooseFile({
- type: 'audio',
- count: 1,
- success: (res) => {
- console.log(res);
- if (res.tempFiles.length > 0) {
- if (this._audioContext == null) {
- this.src = ''
- this._audioContext = uni.createInnerAudioContext()
- this._audioContext!.autoplay = true
- } else if (!this._audioContext!.paused) {
- this._audioContext!.stop()
- }
- this._audioContext!.src = res.tempFiles[0].path
- }
- },
- complete: (res) => {
- console.log(res);
- }
- });
- },
- chooseAll() {
- uni.chooseFile({
- type: 'all',
- count: 1,
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- },
- chooseAllMul() {
- uni.chooseFile({
- type: 'all',
- success: (res) => {
- console.log(res)
- if (res.tempFiles.length > 0) {
- this.log += this.getPath(res.tempFiles) + '\n\n'
- }
- },
- complete: (res) => {
- console.log(res)
- }
- })
- }
- }
- }
- </script>
- <style>
- .btnstyle {
- margin: 4px;
- }
- .video {
- width: 100%;
- height: 225px;
- }
- .uni-uploader__input-box {
- margin: 5px;
- width: 104px;
- height: 104px;
- border: 1px solid #D9D9D9;
- }
- </style>
|