Giter Site home page Giter Site logo

neil-orzzh / giraffeplayer2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tcking/giraffeplayer2

0.0 1.0 0.0 5.1 MB

out of the box android video player(support in ListView/RecyclerView and hight performance)

License: Apache License 2.0

Java 100.00%

giraffeplayer2's Introduction

GiraffePlayer2

Out of the box android video player base on ijkplayer 0.8.4

this project is total refactor of GiraffePlayer to support in ListView/RecyclerView and improve the performance,all player tasks do in worker thread.

release history

features

  1. base on ijkplayer,support RTMP , HLS (http & https) , MP4,M4A etc.
  2. gestures for volume control
  3. gestures for brightness control
  4. gestures for forward or backward
  5. fullscreen by manual or sensor (with animation)
  6. try to replay when error(only for live video)
  7. specify video scale type
  8. support in ListView/RecyclerView (in Activity or Fragment)
  9. never block UI thread
  10. support select track
  11. support float window

how to import library

   //step 1: add jcenter repositories in your root poject build file
   repositories {
       ...
       jcenter()
   }

   //step 2: add dependency
   compile 'com.github.tcking:giraffeplayer2:0.1.11'

   // if need more decoder using: compile 'com.github.tcking:giraffeplayer2:0.1.11-full'

support more ABI: In most cases your app only need to support armeabi-v7a. some articles about ABI :

  1. How to use 32-bit native libaries on 64-bit Android device
  2. What you should know about .so files
  3. 关于Android的.so文件你所需要知道的

to support different ABI:

    compile 'com.github.tcking:ijkplayer-arm64:0.8.4' //support arm64
    compile 'com.github.tcking:ijkplayer-armv5:0.8.4' //support armv5
    compile 'com.github.tcking:ijkplayer-x86:0.8.4' //support x86
    compile 'com.github.tcking:ijkplayer-x86_64:0.8.4' //support x86_64

How to use (example code)

case 1: only want to play a video fullscreen

just call GiraffePlayer.play(getContext(), new VideoInfo("video url"));,all is done.

case 2: embed a player in a layout (ListView/RecyclerView)

step 1: add VideoView in your layout xml file

<tcking.github.com.giraffeplayer2.VideoView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

step 2: get player and play

VideoView videoView = (VideoView) findViewById(R.id.video_view);
videoView.setVideoPath(videoUri).getPlayer().start();

player in ListView or RecyclerView example code

in ListView or RecyclerView,you need do one more thing: call videoView.setFingerprint(), the fingerprint is the key that player distinguish list items,you can using list position or list data's hashcode as fingerprint,eg:

public void onBindViewHolder(VideoItemHolder holder, int position) {
        VideoItem videoItem = data.get(position);
        holder.name.setText(videoItem.name);
        holder.url.setText(videoItem.uri);
        holder.videoView.setVideoPath(videoItem.uri).setFingerprint(position);// or using:setFingerprint(videoItem.hashCode())
    }

config player

all the configurations in VideoInfo,you can get VideoInfo and then set configurations,eg:

//standalone player
VideoInfo videoInfo = new VideoInfo("http://xxx.mp4")
                            .setTitle("test video") //config title
                            .setAspectRatio(aspectRatio) //aspectRatio
                            .setShowTopBar(true) //show mediacontroller top bar
                            .setPortraitWhenFullScreen(true);//portrait when full screen

GiraffePlayer.play(getContext(), videoInfo);

//in RecyclerView or embed player
public void onBindViewHolder(VideoItemHolder holder, int position) {
        VideoItem videoItem = data.get(position);
        holder.name.setText(videoItem.name);
        holder.url.setText(videoItem.uri);
        holder.videoView.getVideoInfo().setBgColor(Color.GRAY).setAspectRatio(VideoInfo.AR_MATCH_PARENT);//config player
        holder.videoView.setVideoPath(videoItem.uri).setFingerprint(position);
    }

all the configurations on VideoInfo :

  1. videoInfo.setAspectRatio() set video view aspect radio
  2. videoInfo.setFingerprint() in list must call this to distinguish items
  3. videoInfo.addOption add player init option
  4. videoInfo.setPortraitWhenFullScreen() control Portrait when full screen
  5. videoInfo.setRetryInterval() retry to play again interval (in second,<=0 will disable retry)
  6. videoInfo.setShowTopBar() show top bar(back arrow and title) when user tap the view
  7. videoInfo.VideoInfo() set video title
  8. videoInfo.setUri() set video Uri
  9. videoInfo.setBgColor() set video background color
  10. videoInfo.setPlayerImpl() VideoInfo.PLAYER_IMPL_IJK:using ijkplayer for decoder,VideoInfo.PLAYER_IMPL_SYSTEM:using android mediaplayer for decoder
  11. videoInfo.addOption() set extra options,only for ijkplayer,eg:addOption(Option.create(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1L))
  12. videoInfo.setFullScreenAnimation() true for play an animation when enter fullscreen or exit fullscreen,only for setPortraitWhenFullScreen(false) and API>=19

API:

GiraffePlayer

  1. player.start()
  2. player.pause()
  3. player.seekTo()
  4. player.setPlayerListener() // in RecyclerView,player will create and release on demand,set listener on videoView:videoView.setPlayerListener()
  5. player.stop() //same as release
  6. player.release() //release the player
  7. player.setVolume() //set volume
  8. player.getTrackInfo() //get all tracks
  9. player.selectTrack() //select track by track index
  10. player.deselectTrack() // deselect track by track index
  11. player.setMute()
  12. player.isMute()
  13. player.getCurrentState() //get current player state
  14. player.setDisplayModel() //set display model:GiraffePlayer.DISPLAY_NORMAL | GiraffePlayer.DISPLAY_FULL_WINDOW | GiraffePlayer.DISPLAY_FLOAT

VideoView (player's display container and media controller)

  1. videoView.getPlayer() get or create bind player
  2. videoView.setFingerprint() delegate of bind videoInfo setFingerprint
  3. videoView.setVideoPath() delegate of bind videoInfo setUri
  4. videoView.isCurrentActivePlayer() is bind player active
  5. videoView.getMediaController() return bind mediaController
  6. videoView.inListView() is video view in ListView or RecyclerView
  7. videoView.setPlayerListener() set player Listener (in ListView or RecyclerView you should call this method rather than player.setPlayerListener

PlayerManager (manage all players,make sure only one player is active)

  1. PlayerManager.getInstance().getCurrentPlayer() return current active player, return null if there is no active player
  2. PlayerManager.getInstance().releaseCurrent() release current active player
  3. PlayerManager.getInstance().isCurrentPlayer(fingerprint) judge player is active by fingerprint
  4. PlayerManager.getInstance().getPlayer(VideoView) get player by video view (will create if not exists)

PlayerListener (player event callback)

void onPreparing();

void onPrepared(GiraffePlayer giraffePlayer);

void onBufferingUpdate(GiraffePlayer giraffePlayer, int percent);

boolean onInfo(GiraffePlayer giraffePlayer, int what, int extra);

void onCompletion(GiraffePlayer giraffePlayer);

void onSeekComplete(GiraffePlayer giraffePlayer);

boolean onError(GiraffePlayer giraffePlayer,int what, int extra);

void onPause(GiraffePlayer giraffePlayer);

void onRelease(GiraffePlayer giraffePlayer);

void onStart(GiraffePlayer giraffePlayer);

void onTargetStateChange(int oldState, int newState);

void onCurrentStateChange(int oldState, int newState);

void onDisplayModelChange(int oldModel, int newModel);

screenshot

TODO

giraffeplayer2's People

Contributors

tcking avatar

Watchers

 avatar

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.