【问题标题】:ImageView or VideoView, which should I display my streaming "video" in android?ImageView 或 VideoView,我应该在 android 中显示我的流媒体“视频”吗?
【发布时间】:2016-10-09 08:15:50
【问题描述】:

我有一个 android 应用程序(本机),它从其他相机流式传输视频。

我用pythonflaskopencv 创建了一个简单的服务器(用于处理视频)

from mockCamera import VideoCamera;

import time
import argparse
from flask import Flask, render_template, Response, jsonify, url_for, send_file



# Gallery folder name
STATIC_FOLDER = 'gallery'


# Init Flask app & Camera object
app = Flask(__name__, static_folder=STATIC_FOLDER)

def gen(camera):
    """Video streaming generator function."""
    while True:
        frame = camera.get_frame()
        yield(b'--frame\r\n'
          b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')


@app.route('/video_feed')
def video_feed():
    """Video streaming route."""
    return Response(gen(VideoCamera()),
                mimetype='multipart/x-mixed-replace; boundary=frame')



if __name__ == '__main__':
    # Construct the argument parser and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-c", "--camera", help="URL of IP Camera")
    args = vars(ap.parse_args())

    # If the camera argument is not None,
    # then we set it to CAMERA_URL variable
    # otherwise we use default value
    if args.get('camera', None) is not None:
    CAMERA_URL = args['camera']

# Run the app
app.run(host='0.0.0.0', debug=True)

camera.get_frame()会返回一个由opencv处理的帧

所以现在,我认为我的 Android 应用将访问 /video_feed 路由,并在 ImageView 中显示视频。

但我不知道这是对还是错。我该怎么做?

提前致谢。

【问题讨论】:

    标签: android python opencv video streaming


    【解决方案1】:

    您通常会使用 VideoView 来显示视频,并使用服务器上视频的 URL 进行设置。

    例如:

            //Create the video player and set the video path
            videoPlayerView = (VideoView) rootView.findViewById(R.id.video_area);
            if (videoPlayerView == null) {
                Log.d("VideoPlayer Activity","onCreateView: videoPlayerView is null");
                return null;
            }
    
            //Set the video URI to the the URL of the video on the server
            videoPlayerView.setVideoURI(yourVideoURL); 
    

    【讨论】:

    • 但是我不知道如何在服务器上设置 URL 视频.. 我该怎么做呢?
    猜你喜欢
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 2011-12-19
    相关资源
    最近更新 更多