Skip to content

Commit

Permalink
add sample
Browse files Browse the repository at this point in the history
  • Loading branch information
agusibrahim committed Jul 15, 2017
1 parent 7ae77a3 commit 1ce67b9
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
/build
*.iml
/.idea

app/build
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ Add in your layout
app:video_quality="small"
android:id="@+id/mainYuuPlayer"/>
```
or Play with full screen
```java
Intent inten=new Intent(context, YuuPlayerFullscreen.class);
inten.putExtra(YuuPlayerFullscreen.PARAM_VIDEO_ID, "eRsGyueVLvQ"); inten.putExtra(YuuPlayerFullscreen.PARAM_VIDEO_QUALITY, "small");
startActivity(inten);
```

For more details about API, check these example
http://github.com/agusibrahim/blablabla

Expand Down
25 changes: 25 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.0"

defaultConfig {
applicationId "id.agusibrahim.yuuplayersample"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\tools\adt-bundle-windows-x86_64-20131030\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
22 changes: 22 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="id.agusibrahim.yuuplayersample" >

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity = "true">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
214 changes: 214 additions & 0 deletions app/src/main/java/id/agusibrahim/yuuplayersample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
package id.agusibrahim.yuuplayersample;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.pm.*;
import android.content.*;
import java.util.*;
import java.text.*;
import id.agusibrahim.yuuplayer.YuuPlayer;
import id.agusibrahim.yuuplayer.YuuPlayerFullscreen;

public class MainActivity extends Activity implements YuuPlayer.OnReceivedData
{
private View loadbtn;
private YuuPlayer yuu;
private Button playbtn,btninfo,downbtn;
private CheckBox mutetoggler;
private View stopbtn;
private EditText tvidid;
private TextView curtime,txtstate;
private SeekBar volctrl;
List<YuuPlayer.Video> myvideo=new ArrayList<YuuPlayer.Video>();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadbtn=findViewById(R.id.mainButton1);
txtstate=(TextView) findViewById(R.id.mainTextView2);
playbtn=(Button) findViewById(R.id.mainButtonplay);
stopbtn=findViewById(R.id.mainButtonstop);
downbtn=(Button) findViewById(R.id.mainButton2);
volctrl=(SeekBar) findViewById(R.id.mainSeekBar1);
tvidid=(EditText) findViewById(R.id.mainEditText1);
curtime=(TextView) findViewById(R.id.mainTextView1);
btninfo=(Button) findViewById(R.id.mainButtoninfo);
mutetoggler=(CheckBox) findViewById(R.id.mainCheckmute);
downbtn.setEnabled(false);
yuu=(YuuPlayer)findViewById(R.id.mainYuuPlayer);
//yuu.setAudioVideoBlockEnable(true);
loadbtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
if(tvidid.getText().length()!=11){
tvidid.setError("Invalid Video ID");
return;
}
yuu.setVideo(tvidid.getText().toString().trim());
}
});
playbtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
if(!yuu.isPlaying) yuu.playVideo();
else yuu.pauseVideo();
}
});
stopbtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
yuu.stopVideo();
}
});
mutetoggler.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton p1, boolean p2) {
yuu.setMute(p2);
}
});
btninfo.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
yuu.getDuration(MainActivity.this);
}
});
downbtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
if(myvideo.size()==0){
Toast.makeText(MainActivity.this, "Video URL not Ready, play video first!",0).show();
return;
}
yuu.pauseVideo();
String[] vids=new String[myvideo.size()];
for(int i=0;i<myvideo.size();i++){
YuuPlayer.Video v=myvideo.get(i);
vids[i]=(v.isAudioOnly?"Audio":"Video")+" ("+v.readableSize+")";
}
AlertDialog.Builder dlg=new AlertDialog.Builder(MainActivity.this);
dlg.setTitle("Download");
dlg.setItems(vids, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2) {
download_(myvideo.get(p2).url);
}
});
dlg.show();
}
});
yuu.setOnReadyListener(new YuuPlayer.OnReadyListener(){
@Override
public void oReady() {
yuu.setVolume(50);
volctrl.setProgress(50);
Toast.makeText(MainActivity.this, "Ready",0).show();
}
});
yuu.setOnVideoURLReadyListener(new YuuPlayer.OnVideoURLReadyListener(){
@Override
public void onVideoURLReady(YuuPlayer.Video vid) {
boolean isExists=false;
for(YuuPlayer.Video v:myvideo){
if(v.size==vid.size) isExists=true;
}
if(!isExists) myvideo.add(vid);
downbtn.setEnabled(true);
}
});
yuu.setOnErrorListener(new YuuPlayer.OnErrorListener(){
@Override
public void onError(String error) {
// Error codes are here https://developers.google.com/youtube/iframe_api_reference#onError
curtime.setText("Player Error: "+error);
}
});

volctrl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar p1, int p2, boolean p3) {
yuu.setVolume(volctrl.getProgress());
}

@Override
public void onStartTrackingTouch(SeekBar p1) {
// TODO: Implement this method
}

@Override
public void onStopTrackingTouch(SeekBar p1) {
// TODO: Implement this method
}
});
yuu.setOnPlayerProgressListener(new YuuPlayer.OnPlayerProgressListener(){
@Override
public void onPlayerProgress(float currentTime) {
curtime.setText(""+toHHMMSS(currentTime));
}
});
yuu.setOnStateChangeListener(new YuuPlayer.OnStateChangeListener(){
@Override
public void onStateChange(int state) {
String textState=""+state;
if(state!=YuuPlayer.STATE_PLAYING){
yuu.unregisterProgressUpdate();
loadbtn.setEnabled(true);
playbtn.setText("Play");
}
switch(state){
case YuuPlayer.STATE_UNSTARTED:
textState="UNSTARTED";
break;
case YuuPlayer.STATE_CUED:
textState="CUED";
break;
case YuuPlayer.STATE_ENDED:
textState="ENDED";
break;
case YuuPlayer.STATE_PAUSED:
textState="PAUSED";
break;
case YuuPlayer.STATE_PLAYING:
textState="PLAYING";
playbtn.setText("Pause");
yuu.registerProgressUpdate(500);
loadbtn.setEnabled(false);
break;
case YuuPlayer.STATE_BUFFERING:
textState="BUFFERING";
break;
}
txtstate.setText(textState);
}
});
}

@Override
public void receivedData(int tag, String data) {
switch(tag){
case YuuPlayer.TAG_DURATION:
Toast.makeText(this, "Video Duration is "+toHHMMSS(Float.parseFloat(data)),0).show();
break;
}
}
private String toHHMMSS(float c){
Date d = new Date((int)c * 1000);
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); // HH for 0-23
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df.format(d);
}

private void download_(String url){
DownloadManager dmgr = (DownloadManager) this.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(android.net.Uri.parse(url));
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false).setTitle("Download")
.setDescription("Downloading Video...")
.setDestinationInExternalPublicDir("/Download/", System.currentTimeMillis()+".mp4");
dmgr.enqueue(request);
}
}
Binary file added app/src/main/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1ce67b9

Please sign in to comment.