VideoView RTMP的Vitamio问题

时间:2018-03-06 02:27:04

标签: android android-studio vitamio

我正在尝试将实时视频从RTMP流式传输到我的Android应用。 到目前为止,这是我的代码:

import io.vov.vitamio.widget.VideoView;

public class LiveActivity extends AppCompatActivity {

    private int responselive;
    private int responsetoggle;
    private String frontlivefeed;
    private String backlivefeed;
    private String toggled = "";
    private boolean enableFront = true;
    private boolean enableBack = true;

    private Button fronttoggle;
    private Button backtoggle;
    private VideoView frontvehicle;
    private VideoView backvehicle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live);

        fronttoggle = (Button) findViewById(R.id.fronttoggleButton);
        backtoggle = (Button) findViewById(R.id.backtoggleButton);
        frontvehicle = (VideoView) findViewById(R.id.frontvideoView);
        backvehicle = (VideoView) findViewById(R.id.backvideoView);

        try
        {
            String templive = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
            String frontlive = "rtmp://18.217.120.158/test/a";
            String backlive = "rtmp://18.217.120.158/test/a";
            final Uri fronturi = Uri.parse(frontlive);
            final Uri backuri = Uri.parse(backlive);

            if(fronturi == null)
            {
                Toast.makeText(LiveActivity.this, "Front connection is null", Toast.LENGTH_SHORT).show();
            }

            else
            {
                frontvehicle.setVideoURI(fronturi);
                frontvehicle.requestFocus();
                frontvehicle.start();

                fronttoggle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view)
                    {
                        if (frontvehicle.isPlaying())
                        {
                            frontvehicle.stopPlayback();
                        }
                        else
                        {
                            frontvehicle.setVideoURI(fronturi);
                            frontvehicle.requestFocus();
                            frontvehicle.start();
                        }
                    }
                });
            }

            if(backuri == null)
            {
                Toast.makeText(LiveActivity.this, "Back connection is null", Toast.LENGTH_SHORT).show();
            }

            else
            {
                backvehicle.setVideoURI(backuri);
                backvehicle.requestFocus();
                backvehicle.start();
            }

            backtoggle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(backvehicle.isPlaying())
                    {
                        backvehicle.stopPlayback();
                    }

                    else
                    {
                        backvehicle.setVideoURI(backuri);
                        backvehicle.requestFocus();
                        backvehicle.start();
                    }
                }
            });
        }

        catch (Exception e)
        {
            Toast.makeText(LiveActivity.this, "Error connecting", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }

        // Leave this comments for now until API is set.
        /*
        new getLiveFeed().execute(((userInfo) getApplication()).gethttp() + "/device/live/feed");
        */
    }

我收到了这些错误:

Error loading libs
    java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: libstlport_shared.so
    java.lang.UnsatisfiedLinkError: No implementation found for void io.vov.vitamio.MediaPlayer.native_init() (tried Java_io_vov_vitamio_MediaPlayer_native_1init and Java_io_vov_vitamio_MediaPlayer_native_1init__)
    at io.vov.vitamio.MediaPlayer.native_init(Native Method)

有谁知道如何解决这些问题,还是有其他方法可以将实时视频流式传输到我的Android应用中?

1 个答案:

答案 0 :(得分:0)

您必须先调用此native library来加载LibsChecker.checkVitamioLibs(this)

这是我从演示应用程序中获得的:

public class VideoViewDemo extends Activity {

private String path = "udp://236.1.0.1:2000";
private VideoView mVideoView;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videoview);
    mVideoView = (VideoView) findViewById(R.id.surface_view);

    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(VideoViewDemo.this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
        return;
    } else {
        mVideoView.setVideoURI(Uri.parse(path));
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

    }
}
}