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

Commit

Permalink
Added currently live panel and better animations
Browse files Browse the repository at this point in the history
  • Loading branch information
markhaehnel committed Feb 1, 2016
1 parent 911bdd5 commit 00ddb25
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 22 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "de.markhaehnel.rbtv.rocketbeanstv"
minSdkVersion 17
targetSdkVersion 17
versionCode 6
versionName "2.2"
versionCode 7
versionName "2.3"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.markhaehnel.rbtv.rocketbeanstv;

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

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

public class GetCurrentShow extends AsyncTask<Void, String, String> {
String lastVisibleShow = "";
protected String doInBackground(Void... voids) {
while (true) {
try {
try {
String response = HttpRequest.get("http://api.twitch.tv/api/channels/rocketbeanstv").body();
JSONObject json = new JSONObject(response);
publishProgress(json.getString("status"));
} catch (JSONException e) {
e.printStackTrace();
}
Thread.sleep(15000);
} catch (Exception e) {
e.printStackTrace();
}
}
}

protected void onProgressUpdate(String... strings) {
String currentShow = strings[0];
if (currentShow.length() != 0) {
lastVisibleShow = currentShow;
MainActivity.getInstance().showCurrentShow(currentShow);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
Expand All @@ -12,13 +13,19 @@
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TableLayout;
import android.widget.TextView;

import com.devbrackets.android.exomedia.EMVideoView;

import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
Expand All @@ -29,6 +36,11 @@ public class MainActivity extends AppCompatActivity implements MediaPlayer.OnPre
AudioManager am;
ComponentName mbr;
EMVideoView emVideoView;
boolean showGetterIsRunning = false;

AlphaAnimation fadeIn;
AlphaAnimation fadeOut;
AlphaAnimation fadeOutShow;

public static MainActivity ins;

Expand All @@ -48,6 +60,8 @@ protected void onCreate(Bundle savedInstanceState) {
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mbr = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());

setupAnimations();

int result = am.requestAudioFocus(focusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
Expand All @@ -57,11 +71,15 @@ protected void onCreate(Bundle savedInstanceState) {
if (json.length() != 0) {
String token = json.getString("token");
String sig = json.getString("sig");
String url = "http://usher.twitch.tv/api/channel/hls/rocketbeanstv.m3u8?player=twitchweb&token=" + token + "&sig=" + sig + "&allow_audio_only=true&allow_source=true&type=any&p=" + Math.round(Math.random() * 10000);
Uri theUri = Uri.parse(url);
emVideoView.setVideoURI(Uri.parse(url));
if (token.length() != 0 && sig.length() != 0) {
String url = "http://usher.twitch.tv/api/channel/hls/rocketbeanstv.m3u8?player=twitchweb&token=" + token + "&sig=" + sig + "&allow_audio_only=true&allow_source=true&type=any&p=" + Math.round(Math.random() * 10000);
Uri theUri = Uri.parse(url);
emVideoView.setVideoURI(Uri.parse(url));
} else {
showMessage(R.string.error_twitchError);
}
} else {
showMessage(R.string.error_accessToken);
showMessage(R.string.error_twitchError);
}

} catch (InterruptedException e) {
Expand All @@ -70,7 +88,7 @@ protected void onCreate(Bundle savedInstanceState) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
showMessage(R.string.error_accessToken);
showMessage(R.string.error_twitchError);
}
}
} else {
Expand Down Expand Up @@ -122,14 +140,10 @@ 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:
case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
pb.startAnimation(fadeOut);
pb.setVisibility(View.INVISIBLE);
if (!showGetterIsRunning) new GetCurrentShow().execute();
break;
}
return false;
Expand All @@ -139,13 +153,27 @@ public void togglePlayState() {
ImageView pauseView = (ImageView)findViewById(R.id.pauseImage);
if (emVideoView.isPlaying()) {
emVideoView.pause();
pauseView.startAnimation(fadeIn);
pauseView.setVisibility(View.VISIBLE);
} else {
emVideoView.start();
pauseView.startAnimation(fadeOut);
pauseView.setVisibility(View.INVISIBLE);
};
}

private void setupAnimations() {
fadeIn = new AlphaAnimation(0.0f, 1.0f);
fadeIn.setDuration(500);

fadeOut = new AlphaAnimation(1.0f, 0.0f);
fadeOut.setDuration(500);

fadeOutShow = new AlphaAnimation(1.0f, 0.0f);
fadeOutShow.setStartOffset(8000);
fadeOutShow.setDuration(500);
}

private void showMessage(int resourceId) {
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setCancelable(false);
Expand Down Expand Up @@ -178,6 +206,18 @@ public boolean isOnline() {
return false;
}

public void showCurrentShow(String showTitle) {
TableLayout containerCurrentShow = (TableLayout)findViewById(R.id.containerCurrentShow);
TextView textCurrentShow = (TextView)findViewById(R.id.textCurrentShow);
textCurrentShow.setText(showTitle);

AnimationSet animation = new AnimationSet(true);
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOutShow);

containerCurrentShow.setAnimation(animation);
}

AudioManager.OnAudioFocusChangeListener focusListener = new AudioManager.OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focus) {
switch (focus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public void onReceive(Context context, Intent intent) {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
MainActivity.getInstance().togglePlayState();
break;
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
//Should go back to live after paused
break;
}
}
}
Expand Down
54 changes: 50 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
android:layout_height="wrap_content"
android:id="@+id/pauseImage"
android:layout_gravity="center"
android:src="@drawable/exomedia_ic_pause_black"
android:minHeight="128dp"
android:minWidth="128dp"
android:background="#b2ffffff"
android:src="@drawable/exomedia_ic_pause_white"
android:background="#de000000"
android:visibility="invisible"
android:contentDescription="Pause" />

Expand All @@ -35,6 +33,54 @@
android:id="@+id/progressBar"
android:layout_gravity="center" />

<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:background="#de000000"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:layout_marginRight="32dp"
android:layout_marginTop="32dp"
android:id="@+id/containerCurrentShow"
android:visibility="invisible">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Aktuelle Sendung"
android:id="@+id/textView"
android:layout_column="2"
android:textAlignment="textEnd"
android:textColor="#b2ffffff"
android:textStyle="italic" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/app_name"
android:id="@+id/textCurrentShow"
android:autoText="true"
android:textColor="#b2ffffff"
android:visibility="visible"
android:layout_column="2" />
</TableRow>

</TableLayout>

</FrameLayout>

</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<string name="app_name">Rocket Beans TV</string>
<string name="error_accessToken">Ups, da ist etwas schief gelaufen. Hat Twitch etwa Probleme?\n\nVersuch es später erneut.</string>
<string name="error_twitchError">Ups, da ist etwas schief gelaufen. Hat Twitch etwa Probleme?\n\nVersuch es später erneut.</string>
<string name="error_noInternet">Anscheinend hast du keine Verbindung zum Internet.\nDadurch kann leider keine Verbindung zum Stream aufgebaut werden.</string>
<string name="error_unknown">Ein unbekannter Fehler ist aufgetreteten.\n\nBitte versuche es später erneut.</string>
</resources>

0 comments on commit 00ddb25

Please sign in to comment.