suwu150 2018-08-01 04:53 采纳率: 20%
浏览 1125
已结题

react-native访问安卓原生VideoView组件报错,错误如下所示

react-native访问安卓原生VideoView组件报错,错误如下所示,请问什么原因??

08-01 12:54:24.034 4321-4321/com.react_native_video I/MediaPlayer: constructor
08-01 12:54:24.038 4321-4321/com.react_native_video I/MediaPlayer: setDataSource:http://ohe65w0xx.bkt.clouddn.com/test3.mp4
08-01 12:54:24.038 4321-4321/com.react_native_video W/MediaPlayer: Couldn't open http://ohe65w0xx.bkt.clouddn.com/test3.mp4: java.io.FileNotFoundException: No content provider: http://ohe65w0xx.bkt.clouddn.com/test3.mp4
08-01 12:54:24.038 4321-4321/com.react_native_video I/MediaPlayer: setDataSource:http://ohe65w0xx.bkt.clouddn.com/test3.mp4
08-01 12:54:24.039 4321-4321/com.react_native_video V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@63789e0): Cookies: null
08-01 12:54:24.043 4321-4351/com.react_native_video V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager@4e82499
    makeHTTP

我的环境信息如下:

     npmPackages:
      react: 16.4.1 => 16.4.1 
      react-native: 0.56.0 => 0.56.0 
    npmGlobalPackages:
      react-native-cli: 2.0.1

并且,我的视频地址
http://ohe65w0xx.bkt.clouddn.com/test3.mp4
也是可以访问到的,
下面是我的原生代码

package com.react_native_video;
import android.net.Uri;
import javax.annotation.Nullable;

import android.os.Build;
import android.widget.VideoView;

import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;

import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class VideoViewManager extends SimpleViewManager<VideoView> {
    @Override
    public String getName() {// 组件名称
        return "VideoView";
    }

    @Override
    protected VideoView createViewInstance(ThemedReactContext reactContext) {
        VideoView video = new VideoView(reactContext);
        return video;
    }


    @Override
    public void onDropViewInstance(VideoView view) {//对象销毁时
        super.onDropViewInstance(view);
        view.stopPlayback();//停止播放
    }

//    @ReactProp(name="source")
//    public void setSource(VideoView videoView, @Nullable String source) {
//        if (source!= null) {
//            videoView.setVideoURI(Uri.parse(source));
//            videoView.start();
//        }
//    }

    @ReactProp(name="source")
    public void setSource(VideoView videoView, @Nullable ReadableMap source) {
        if (source!= null) {
            if (source.hasKey("url")) {
                String url = source.getString("url");
                System.out.println("========================" + url);
                FLog.e(VideoViewManager.class, "url=" + url);
                HashMap<String, String> headerMap = new HashMap<>();
                if (source.hasKey("headers")) {
                    ReadableMap headers =source.getMap("headers");
                    ReadableMapKeySetIterator iter = headers.keySetIterator();
                    while(iter.hasNextKey()) {
                        String key = iter.nextKey();
                        String value = headers.getString(key);
                        FLog.e(VideoViewManager.class, key+"=" + value);
                        System.out.println("========================");
                        System.out.println(key+"=" + value);
                        System.out.println("========================");
                        headerMap.put(key, value);
                    }
                }
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    // videoView.setVideoURI(Uri.parse(url));
                    // Uri.fromFile(new File(url)))
                    System.out.println("========+++++================");
                    System.out.println(Uri.fromFile(new File(url)));
                    System.out.println(Uri.parse(url));
                    System.out.println("========+++===================");
                    videoView.setVideoURI(Uri.parse(url), headerMap);
                } else {
                    try {
                        // Uri.fromFile(new File(your image path))
                        Method setVideoURIMethod = videoView.getClass()
                                .getMethod("setVideoURI", Uri.class, Map.class);
                        setVideoURIMethod.invoke(videoView, Uri.parse(url), headerMap);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("=============videoView===========");
                System.out.println(videoView);
                videoView.start();
                //设置获取焦点
                videoView.setFocusable(true);
            }
        }
    }

}



  • 写回答

2条回答 默认 最新

  • dabocaiqq 2018-08-03 09:17
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接