Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Added buffering spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
markhaehnel committed Jan 31, 2016
1 parent fd18559 commit 911bdd5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutCompat;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.devbrackets.android.exomedia.EMVideoView;
import com.devbrackets.android.exomedia.listener.ExoPlayerListener;
import com.google.android.exoplayer.ExoPlayer;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class MainActivity extends AppCompatActivity implements MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener {
public class MainActivity extends AppCompatActivity implements MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnInfoListener {


AudioManager am;
Expand All @@ -46,6 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (isOnline()) {
emVideoView.setOnPreparedListener(this);
emVideoView.setOnErrorListener(this);
emVideoView.setOnInfoListener(this);

am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mbr = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
Expand Down Expand Up @@ -84,6 +82,16 @@ public static MainActivity getInstance() {
return ins;
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
togglePlayState();
return true;
}
return false;
}

@Override
public void onPrepared(MediaPlayer mp) {
EMVideoView emVideoView = (EMVideoView)findViewById(R.id.exomediaplayer);
Expand All @@ -103,6 +111,30 @@ public void onResume() {
super.onResume();
}

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
showMessage(R.string.error_unknown);
return true;
}

@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
ProgressBar pb = (ProgressBar)findViewById(R.id.progressBar);

switch (what) {
case MediaPlayer.MEDIA_INFO_BUFFERING_START:
pb.setVisibility(View.VISIBLE);
break;
case MediaPlayer.MEDIA_INFO_BUFFERING_END:
pb.setVisibility(View.INVISIBLE);
break;
default:
pb.setVisibility(View.INVISIBLE);
break;
}
return false;
}

public void togglePlayState() {
ImageView pauseView = (ImageView)findViewById(R.id.pauseImage);
if (emVideoView.isPlaying()) {
Expand Down Expand Up @@ -164,12 +196,6 @@ public void onAudioFocusChange(int focus) {
}
}
};

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
showMessage(R.string.error_unknown);
return true;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ public void onReceive(Context context, Intent intent) {
if (key.getAction() == KeyEvent.ACTION_DOWN) {
switch (keycode) {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
MainActivity mainActivity = MainActivity.getInstance();
mainActivity.togglePlayState();
MainActivity.getInstance().togglePlayState();
break;
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
//Should go back to live after paused
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_gravity="center"
android:visibility="invisible" />
android:layout_gravity="center" />

</FrameLayout>

Expand Down

0 comments on commit 911bdd5

Please sign in to comment.