Giter Club home page Giter Club logo

ijkplayerview's Introduction

IjkPlayerView

Apache 2.0 License

IjkPlayerView is an media player for Android base on ijkplayer. It used to play video both locally and over the Internet.

Screenshot

Using IjkPlayerView

You need to make sure you have the JitPack repository included inthe build.gradle file in the root of your project:

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

Next, include the following in your module's build.gradle file:

compile 'com.github.Rukey7:IjkPlayerView:{lastest-version}'

where {lastest-version} is the your preferred version. For the latest version, see the project's [Releases][]. For more details, see the project on jitpack.io.

Usage

Add the configuration to your Activity in the AndroidManifest.xml:

	<activity  
	    android:name=".IjkPlayerActivity"  
	    android:configChanges="orientation|keyboardHidden|screenSize"/>

Using IjkPlayerView is like to use other widgets in your layout:

	<com.dl7.player.media.IjkPlayerView  
	    android:id="@+id/player_view"  
	    android:layout_width="match_parent"  
	    android:layout_height="200dp"/>  

Finally, you should do this in your activity:

	public class IjkPlayerActivity extends AppCompatActivity {  
  
	    private IjkPlayerView mPlayerView;  
	  
	    @Override  
	    protected void onCreate(Bundle savedInstanceState) {  
	        super.onCreate(savedInstanceState);  
	        setContentView(R.layout.activity_ijk_player);  
	        setSupportActionBar(mToolbar);  
	        //  Choose any one interface you need, init() must be the first to use.
	        Glide.with(this).load(IMAGE_URL).fitCenter().into(mPlayerView.mPlayerThumb); // Show the thumb before play
	        mPlayerView.init()              // Initialize, the first to use 
	                .setTitle("Title")  	// set title  
	                .setSkipTip(1000*60*1)  // set the position you want to skip  
	                .enableOrientation()    // enable orientation 
	          //      .setVideoPath(VIDEO_URL)    // set video url  
	                .setVideoSource(null, VIDEO_URL, VIDEO_URL, VIDEO_URL, null) // set multiple video url  
	                .setMediaQuality(IjkPlayerView.MEDIA_QUALITY_HIGH)  // set the initial video url
	                .enableDanmaku()        // enable Danmaku  
	                .setDanmakuSource(getResources().openRawResource(R.raw.comments)) // add Danmaku source, you need to use enableDanmaku() first 
	                .start();   // Start playing 
	    }  
	  
	    @Override  
	    protected void onResume() {  
	        super.onResume();  
	        mPlayerView.onResume();  
	    }  
	  
	    @Override  
	    protected void onPause() {  
	        super.onPause();  
	        mPlayerView.onPause();  
	    }  
	  
	    @Override  
	    protected void onDestroy() {  
	        super.onDestroy();  
	        mPlayerView.onDestroy();  
	    }  
	  
	    @Override  
	    public void onConfigurationChanged(Configuration newConfig) {  
	        super.onConfigurationChanged(newConfig);  
	        mPlayerView.configurationChanged(newConfig);  
	    }  
	  
	    @Override  
	    public boolean onKeyDown(int keyCode, KeyEvent event) {  
	        if (mPlayerView.handleVolumeKey(keyCode)) {  
	            return true;  
	        }  
	        return super.onKeyDown(keyCode, event);  
	    }  
	  
	    @Override  
	    public void onBackPressed() {  
	        if (mPlayerView.onBackPressed()) {  
	            return;  
	        }  
	        super.onBackPressed();  
	    } 
 	}   

If you want keep fullscreen, you can do this:

	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPlayerView = new IjkPlayerView(this);
        setContentView(mPlayerView);
        Glide.with(this).load(IMAGE_URL).fitCenter().into(mPlayerView.mPlayerThumb);
        mPlayerView.init()
                .setTitle("Title")
                .alwaysFullScreen()			// keep fullscreen
                .setVideoPath(VIDEO_URL)	
                .start();
    }

You can use custom data type of Danmaku. For more details please see the example.

	
    mPlayerView.init()
            .enableDanmaku()
            .setDanmakuCustomParser(new DanmakuParser(), DanmakuLoader.instance(), DanmakuConverter.instance())
            .setDanmakuSource(stream)
            .setVideoPath(VIDEO_URL)	
            .setDanmakuListener(new OnDanmakuListener<DanmakuData>() {
                    @Override
                    public boolean isValid() {
                        return true;
                    }

                    @Override
                    public void onDataObtain(DanmakuData data) {
                    }
                });

Other

There will be some problems in fullscreen when you use do the following options:

Ensure IjkPlayerView is on the top of your layout except ToolBar.

Thanks

License

Copyright 2016 Rukey7

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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.