Giter VIP home page Giter VIP logo

android-simple-mjpegviewer's Introduction

Android-Simple-MjpegViewer

Installation

Step1. Add it in your root build.gradle at the end of repositories

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Step2. Add the dependency in your module build.gradle

dependencies {
    compile 'com.github.dydwo92:Android-Simple-MjpegViewer:0.0'
}

Step 3. Build your project through Build > Make Project. And then, sync your project through Tools > Android > Sync Project with Gradle Files

Step 4. In AndroidManifest.xml in your app, add the following line to access internet.

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

Also, add the following tag. It will prevent video reloading when screen rotating.

<activity
    ...
    android:configChanges="orientation|screenSize"
>

Usage

Add MjpegViewer component. In the layout xml, put the MjpegView tag.

    <MjpegViewer.MjpegView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/videwView" />

Start video streaming. In the activity class, start the video streaming.

public class MainActivity extends AppCompatActivity {
    MjpegView mv;

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

        mv = (MjpegView) findViewById(R.id.videwView);
        
        // By the time you do this, the mjpeg stream url below may not work..
        mv.Start("http://webcam.st-malo.com/axis-cgi/mjpg/video.cgi?resolution=352x288");
    }
}

Methods

There are only three methods to control the MjpegView component.

1. Start

mv.Start(String url);
mv.Start(String url, Handler parent_handler);

You can start the video streaming simply with Start() method. You can see there are two Start() methods above. If you want to handle events, insert the handle object in the Start() method. Handling events is described below(Event Handling).

2. Stop

mv.Stop();

You can stop the video streaming.

3. SetDisplayMode

mv.SetDisplayMode(mv.SIZE_FIT);
mv.SetDisplayMode(mv.SIZE_FULL);

When you set the display mode to SIZE_FIT, MjpegViewer will display the video to fit the screen properly. If you set the display mode to SIZE_FULL, MjpegViewer will crop the video appropriately and display it full on the screen.

Event Handling

public class MainActivity extends AppCompatActivity {
    MjpegView mv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mv = (MjpegView) findViewById(R.id.videwView);
        mv.Start("http://webcam.st-malo.com/axis-cgi/mjpg/video.cgi?resolution=352x288", MjpegViewHandler);
    }

    final Handler MjpegViewHandler = new Handler(){
        @Override
        public void handleMessage(Message msg){
            Log.d("State : ", msg.obj.toString());
            
            switch (msg.obj.toString()){
                case "DISCONNECTED" :
                    // TODO : When video stream disconnected
                    break;
                case "CONNECTION_PROGRESS" :
                    // TODO : When connection progress
                    break;
                case "CONNECTED" :
                    // TODO : When video streaming connected
                    break;
                case "CONNECTION_ERROR" :
                    // TODO : When connection error
                    break;
                case "STOPPING_PROGRESS" :
                    // TODO : When MjpegViewer is in stopping progress
                    break;
            }
            
        }
    };

}

android-simple-mjpegviewer's People

Contributors

dydwo92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

android-simple-mjpegviewer's Issues

not playing the live stream in real device

I have used this repo to play live streamed video from my raspberry pi and i tested it on my avd it plays fine but in my real android device it just shows blank screen is there any reason this happens how can i tackle it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.