android - ExoPlayer doesn work on some devices -


i want implement video player (exoplayer) in android app. player must play video (not big, ~2-3 minutes) url. on nexus 5 works well, on phone "samsung gt-i8552 galaxy win" unfortunately doesnt work. there exception logs after compiling , starting app:

internal runtime error.
java.lang.illegalstateexception

at android.media.mediacodec.dequeueoutputbuffer(native method)

and code:

      private surfaceview surfaceview;       private exoplayer player;       private mediacodecvideotrackrenderer videorenderer;       private mediacodecaudiotrackrenderer audiorenderer;       private custommediacontroller mediacontroller;       private string useragent;       private final int renderer_count = 8;       private static final int buffer_segment_size = 64 * 1024;       private static final int buffer_segment_count =  256;         private static final int minbufferms = 10000;       private static final int minrebufferms = 5000;       private final string videourl_2 = "someurl..."; 

...

    surfaceview = (surfaceview) findviewbyid(r.id.surface_view);     player = exoplayer.factory.newinstance(renderer_count, minbufferms, minrebufferms);     useragent = util.getuseragent(this, "myplayer");     allocator allocator = new defaultallocator(buffer_segment_size);     datasource datasource = new defaulturidatasource(context, null, useragent);      extractorsamplesource samplesource = new extractorsamplesource(uri.parse(videourl_2), datasource, allocator, buffer_segment_count * buffer_segment_size);     videorenderer = new mediacodecvideotrackrenderer(context,             samplesource, mediacodecselector.default, mediacodec.video_scaling_mode_scale_to_fit_with_cropping);     audiorenderer = new mediacodecaudiotrackrenderer(samplesource, mediacodecselector.default);     player.prepare(videorenderer, audiorenderer);     player.sendmessage(videorenderer, mediacodecvideotrackrenderer.msg_set_surface, surfaceview.getholder().getsurface());      player.setplaywhenready(true);      custommediaplayercontrol custommediaplayercontrol = new custommediaplayercontrol(player);     mediacontroller = new custommediacontroller(context);     mediacontroller.setmediaplayer(custommediaplayercontrol);     mediacontroller.setanchorview(surfaceview);     mediacontroller.setenabled(true); 

my class custommediaplayercontrol:

public class custommediaplayercontrol implements mediacontroller.mediaplayercontrol { private exoplayer player;  public custommediaplayercontrol(exoplayer player) {     this.player = player; }  @override public void start() {     player.setplaywhenready(true); }  @override public void pause() {     player.setplaywhenready(false); }  @override public int getduration() {     return (int) player.getduration(); }  @override public int getcurrentposition() {     return (int) player.getcurrentposition(); }  @override public void seekto(int pos) {     player.seekto(pos); }  @override public boolean isplaying() {     return player.getplaywhenready(); }  @override public int getbufferpercentage() {     return (int) player.getbufferedpercentage(); }  @override public boolean canpause() {     return true; }  @override public boolean canseekbackward() {     return true; }  @override public boolean canseekforward() {     return true; }  @override public int getaudiosessionid() {     return 0; } } 

and class custommediacontroller:

public class custommediacontroller extends mediacontroller {  private mediacontroller.mediaplayercontrol playercontrol;  public custommediacontroller(context context) {     super(context); }  @override public void setmediaplayer(mediacontroller.mediaplayercontrol playercontrol) {     super.setmediaplayer(playercontrol);     this.playercontrol = playercontrol; }  @override public boolean dispatchkeyevent(keyevent event) {     int keycode = event.getkeycode();     if (playercontrol.canseekforward() && keycode == keyevent.keycode_media_fast_forward) {         if (event.getaction() == keyevent.action_down) {             playercontrol.seekto(playercontrol.getcurrentposition() + 15000); // milliseconds             show();         }         return true;     } else if (playercontrol.canseekbackward() && keycode == keyevent.keycode_media_rewind) {         if (event.getaction() == keyevent.action_down) {             playercontrol.seekto(playercontrol.getcurrentposition() - 5000); // milliseconds             show();         }         return true;     }     return super.dispatchkeyevent(event); } } 

exoplayer have minimal sdk level 16 requirement.

exoplayer’s standard audio , video components rely on android’s mediacodec api, released in android 4.1 (api level 16). hence not work on earlier versions of android.
from: https://google.github.io/exoplayer/guide.html


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -