当我使用https时,VideoView上的“无法播放此视频”

时间:2018-11-12 15:09:59

标签: android android-studio react-native android-videoview

我是编程新手,目前在React Native的组件中使用VideoView。该组件可以正常工作,但是我注意到,当视频链接为 https 时,它不会加载,但当 http 时,它会正常加载。

什么可能导致这种奇怪的行为?

我组件的代码:

public class VideoViewManager extends SimpleViewManager<VideoView> {
public static final String REACT_CLASS = "VideoView";
private ThemedReactContext mContext = null;

@Override
public String getName() {
    return REACT_CLASS;
}

@Override
protected VideoView createViewInstance(ThemedReactContext reactContext) {
    mContext = reactContext;
    VideoView videoView = new VideoView(reactContext);

    return videoView;
}

@ReactProp(name="url")
public void setVideoPath(VideoView videoView, String urlPath) {
  Uri uri = Uri.parse(urlPath);
  videoView.setMediaController(new MediaController(mContext));
  videoView.setVideoURI(uri);
  videoView.start();
 }
}

还有

public class VideoViewPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
    return Collections.<ViewManager>singletonList(new VideoViewManager());
}
}

我在js中的组件:

import PropTypes from 'prop-types';
import { requireNativeComponent, ViewPropTypes } from 'react-native';
var viewProps = {
    name: 'VideoView',
    propTypes: {
        url: PropTypes.string,

  }
}
module.exports = requireNativeComponent('VideoView', viewProps);

并使用:

export default class App extends Component<Props> {


render() {
    return (
      <View
        style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <VideoViewer style={{ flex: 1, width: '100%', height: '100%' }}
          url="https://www.radiantmediaplayer.com/media/bbb-360p.mp4" />
      </View>
    );
  }
}

我感谢任何能帮助我的人。

0 个答案:

没有答案