转: 原生API 播放 rstp

o---- http://brianchen85.blogspot.jp/2015/03/android-play-rtsp-vedio.html

之前有介紹過使用Vitamio第三方元件
雖然功能強大,但必須回歸到原生本質
這次要寫一個簡單的Sample
至於有沒有測試的連結,這可能要到Google 搜尋

RTSP是即時串流的協議
畫面會延遲有可能的原因 :
1 . 網路延遲
2 . 手機硬體規格
3 . 過多裝置連到監控裝置

話不多說,直接來看範例吧 !

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/playButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Play" />

    <VideoView
        android:id="@+id/rtspVideo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

MainActivity.java

package com.example.rtsp;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.VideoView;

public class MainActivity extends Activity implements OnClickListener{

    EditText rtspUrl ;
    Button playButton ;
    VideoView videoView ;  

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);  

        rtspUrl = (EditText)this.findViewById(R.id.editText);
        videoView = (VideoView)this.findViewById(R.id.rtspVideo);
        playButton = (Button)this.findViewById(R.id.playButton);
        playButton.setOnClickListener(this);

    }  

    @Override
    public void onClick(View view) {
        switch(view.getId()){
        case R.id.playButton:
            RtspStream(rtspUrl.getEditableText().toString());
            break;
        }
    }  

    private void RtspStream(String rtspUrl){
        videoView.setVideoURI(Uri.parse(rtspUrl));
        videoView.requestFocus();
        videoView.start();
    }

}

記得一定要新增權限 :

<uses-permission android:name="android.permission.INTERNET" />

完成圖

时间: 2024-08-01 20:18:28

转: 原生API 播放 rstp的相关文章

ZooKeeper实现配置中心的实例(原生API实现)(转)

说明:要实现配置中心的例子,可以选择的SDK有很多,原生自带的SDK也是不错的选择.比如使用I0Itec,Spring Boot集成等. 大型应用通常会按业务拆分成一个个业务子系统,这些大大小小的子应用,往往会使用一些公用的资源,比如:需要文件上传.下载时,各子应用都会访问公用的Ftp服务器.如果把Ftp Server的连接IP.端口号.用户名.密码等信息,配置在各子应用中,然后这些子应用再部署到服务器集群中的N台Server上,突然有一天,Ftp服务器要换IP或端口号,那么问题来了?),而是如

ZooKeeper客户端原生API的使用以及ZkClient第三方API的使用

这两部分内容的介绍主要讲的是节点及节点内容和子节点的操作,并且讲解的节点的事件监听以及ACL授权 ZooKeeper客户端原生API的使用 百度网盘地址: http://pan.baidu.com/s/1jI3b8n8 ZkClient第三方API的使用 ZkClient是Github上一个开源的ZooKeeper客户端.ZkClient在ZooKeeper原生API之上进行了包装,是一个更加易用的ZooKeeper客户端.同时ZkClient在内部实现了诸如Session超时重连.Watche

(原) 2.1 Zookeeper原生API使用

本文为原创文章,未经允许不得转载 Zookeeper原生API使用 1.jar包引入,演示版本为3.4.6,非maven项目,可以下载jar包导入到项目中 <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> </dependency> 2.

ios网络学习------11 原生API文件上传之断点续传思路

#import "MainViewController.h" @interface MainViewController () @end @implementation MainViewController - (void)viewDidLoad { [super viewDidLoad]; //下载文件 [self download]; } -(void)download { //1. NSURL NSURL *url = [NSURL URLWithString:@"ht

使用IOS7原生API进行二维码条形码的扫描

使用IOS7原生API进行二维码条形码的扫描 IOS7之前,开发者进行扫码编程时,一般会借助第三方库.常用的是ZBarSDK,IOS7之后,系统的AVMetadataObject类中,为我们提供了解析二维码的接口.经过测试,使用原生API扫描和处理的效率非常高,远远高于第三方库. 一.使用方法示例 官方提供的接口非常简单,代码如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

springmvc使用pojo和servlet原生api作为参数

一.Pojo作为参数: 实体: package com.hy.springmvc.entities; public class User { private String username; private String password; private String email; private Address address; public String getUsername() { return username; } public void setUsername(String us

Spring MVC 使用Servlet原生API作为参数

具体看代码: 1 @RequestMapping("/testServletAPI") 2 public void testServletAPI(HttpServletRequest request, 3 HttpServletResponse response,HttpSession session, 4 Write r out) throws IOException{ 5 System.out.println(request); 6 System.out.println(respo

phonegap+cordova+ionic调用原生API

上一篇博客讲了phonegap+cordova+ionic的环境搭建,今天再来分享一篇cordova调用原生API的文章.从技术角度上来讲,这并不是很难,只是有些细节要是没有注意,或者某些步骤不知道的,那么在坑里一时半会很难爬出来.所以这两篇博客旨在帮助小伙伴们节省更多的时间去做其他有意义的事情. 1.新建工程 新建工程和添加平台支持的操作已经在上一篇博客中讲到了, 这里不再赘述. 2.Bower的使用 首先确认是否安装了bower,如果没有安装,打开cmd命名,输入npm install -g

微软发布WP SDK8.0 新增语音、应用内支付等原生API

http://www.csdn.net/article/2012-10-31/2811338-windows-phone-8-sdk 京时间10月30日,微软在旧金山举行新一代手机操作系统Windows Phone 8发布会,试图在竞争如此激烈的智能手机市场上多分一杯羹.除了推出新一代的Windows Phone 8外,微软官方表示,开发者还可以下载Windows Phone SDK 8.0. Windows Phone 8新特性: Data Sense.内置Xbox.Live Tiles Wi