I spent hours working on creating a proper streaming video player in android and quite successful in creating a player that can play very small content like songs, trailers, etc. But the player exhibits unusual behavior for large content such as movies and TV shows, since it requires a lot of streaming, the player begins to lag behind such data. Can anyone help me crack a solution to this problem.
Thanks in Advance ...
Here is the source:
public class player extends Activity implements OnErrorListener, OnPreparedListener { private static final int UPDATE_FREQUENCY = 500; private static final int STEP_VALUE = 4000; private static final int DIALOG_KEY = 0; private TextView currentTime, duration; private VideoView videoView; private SeekBar seekbar = null; private View mediacontroller; private ProgressDialog progressDialog = null; private ImageButton playButton = null; private ImageButton prevButton = null; private ImageButton nextButton = null; private boolean isMoveingSeekBar = false; private boolean isMediaCtrlShown = false; private final Handler handler = new Handler(); private boolean isStarted = true; private String currentFile = "singham_320b"; private boolean isCustomSeekButtonClick = false; private boolean isPauseButtonClick = false; private static boolean isMyDialogShowing = false; private static int percentageBuffer = 0; private int mpCurrentPosition; int hh = 00, mm = 00, ss = 00, ms = 00; int i = 0; int previouPosition = 0; private Runnable onEverySecond=new Runnable() { public void run() { if (videoView!=null) { seekbar.setProgress(videoView.getCurrentPosition()); } if (!isPauseButtonClick) { mediacontroller.postDelayed(onEverySecond, 1000); } } }; private final Runnable updatePositionRunnable = new Runnable() { public void run() { updatePosition(); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setUpMyDialog(); showMyDialog(); videoView = (VideoView) findViewById(R.id.videoview); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); seekbar = (SeekBar) findViewById(R.id.seekbar); currentTime = (TextView) findViewById(R.id.currentTime); playButton = (ImageButton) findViewById(R.id.play); prevButton = (ImageButton) findViewById(R.id.prev); nextButton = (ImageButton) findViewById(R.id.next); duration = (TextView) findViewById(R.id.duration); mediacontroller = findViewById(R.id.mediacontroller); videoView.setOnErrorListener(this); videoView.setOnPreparedListener(this); videoView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!isMediaCtrlShown) { mediacontroller.setVisibility(View.GONE); isMediaCtrlShown = true; } else { mediacontroller.setVisibility(View.VISIBLE); isMediaCtrlShown = false; } return false; } }); Uri video = Uri.parse("http://wpc.1B42.edgecastcdn.net/001B42/mobile/songs/pyaar_ka_punchnama/life_sahi_hai_320b.mp4"); videoView.setVideoURI(video); seekbar.setOnSeekBarChangeListener(seekBarChanged); playButton.setOnClickListener(onButtonClick); nextButton.setOnClickListener(onButtonClick); prevButton.setOnClickListener(onButtonClick); } @Override public boolean onError(MediaPlayer mp, int what, int extra) {
Jitu
source share