YouTubeStandAlonePlayer(Android Player API) lightbox mode doesn't a have fullscreen button? - android

I'm trying out the Android Player API and I noticed that while using the YouTubeStandAlonePlayer class, there's no fullscreen button in the player UI when playing the video in lightbox mode.
Is there a way you can customize the player UI to show the fullscreen button?
I look up the docs but don't see any more info
public class MainActivity extends Activity implements View.OnClickListener {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playVideoButton = (Button) findViewById(R.id.start_video_button);
playVideoButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Intent intent = null;
if (v == playVideoButton) {
intent = YouTubeStandalonePlayer.createVideoIntent(
this, DEVELOPER_KEY, VIDEO_ID, 0, true, true);
}
}

Related

how can I stop music in one activity and start another music in next activity?

I have 3 activity, when I move from 1st act.to 2nd act. one music will start, and when I move from 2nd act. to 3rd act., 2nd activity's music should stop and 3rd activity's music should start. As per my coding, 2nd activity's music is stopping, but 3rd activity's music does not start. my code is given here-under: please help me.
//1st activity code start
public class MainActivity extends AppCompatActivity {
Button b;
static MediaPlayer mp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onResume() {
super.onResume();
final MediaPlayer mp = MediaPlayer.create(this,R.raw.bakaratwozeroone);
b = (Button) findViewById(R.id.butmove);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mp.start();
startActivity(new Intent(MainActivity.this,Main2Activity.class));
}
});
}
}
//1st activity code end
//2nd activity code start
public class Main2Activity extends AppCompatActivity {
Button b;
static MediaPlayer mp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
#Override
protected void onResume() {
super.onResume();
final MediaPlayer mp = MediaPlayer.create(this, R.raw.mumfive);
b = (Button) findViewById(R.id.butmove2);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mp.start();
startActivity(new Intent(Main2Activity.this, Main3Activity.class));
}
});
}
#Override
protected void onPause() {
super.onPause();
if(mp !=null);
mp.release();
mp = null;
}
}
//2nd activity code end
No need to keep MediaPlayer instance on every activity, Use BoundService to run media player and make communication with Service and activities.
For reference,use this link
https://github.com/SimpleMobileTools/Simple-Music-Player

Run an audio file instantly when clicking on the application button (Android)

How to run an audio file instantly when clicking on the application button and not when button returns with Android Media Player
Any help is welcome because I did not find solution.
1.you add button
2.
public class Setting extends Activity implements OnClickListener{
private MediaPlayer Music;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_setting);
Music = MediaPlayer.create(this, R.raw.musicname);
findViewById(R.id.button).setOnClickListener(this);
}
public void onClick(View view) {
if (view.getId() == R.id.button) {
Music.start();
}
}
}
only Preview :D

Showing launcher screen only once in Android

I want to show launcher screen in Android app only once. Then if the user is on the second screen, if he presses back button, I want app to close. What's wrong in this code? The first screen shows again, what mustn't be.
public class MainActivity extends Activity {
private boolean firstscreenshown=false;
#Override
protected void onCreate(Bundle savedInstanceState) {
if (firstscreenshown==true) finish();
firstscreenshown=true;
or
public class MainActivity extends Activity {
private boolean firstscreenshown;
public MainActivity() {
this.firstscreenshown = false;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
if (firstscreenshown==true) finish();
firstscreenshown=true;
Use this code for handle back button in your MainActivity class:
#Override
public void onBackPressed()
{
// TODO Auto-generated method stub
super.onBackPressed();
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
I have a disclaimer view that I display the first time my app is run. Here is how I handle it:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// check preferences to see if disclaimer has been display
boolean showDisclaimer = getPreferences(MODE_PRIVATE).getBoolean("disclaimer", true);
if (showDisclaimer) {
// turn off the disclaimer
getPreferences(MODE_PRIVATE).edit().putBoolean("disclaimer",false).commit();
// display the disclaimer
Intent intent = new Intent(MainActivity.this, LegalActivity.class);
startActivity(intent);
}
setContentView(R.layout.activity_main);
}
Here is the activity for the disclaimer:
public class LegalActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.legal_detail);
// Watch for guide button clicks.
Button button = (Button) this.findViewById(R.id.legal_button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
My disclaimer view has a done button which closes it.
Hope this helps!
Call finish after your call to the second activity, so when the second screen appears the previous one will be erased.
startActivity(intent)
The best and simplest way to achieve this would be to override onPause() method and call :
finish();
inside the first activity!

landscape mode video activity is restarting

I am playing videos in my app, video should play portrait and landscape mode withought restarting actvity, please any can give examples are links.
using video view for playing video.
public class PlayVideoActivity extends Activity {
private VideoView video;
private ImageButton back;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
back = (ImageButton)findViewById(R.id.backbutton);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
video=(VideoView)findViewById(R.id.videoView);
video.setDrawingCacheEnabled(true);
video.setDrawingCacheQuality(VideoView.DRAWING_CACHE_QUALITY_HIGH);
video.setVideoURI(Uri.parse("android.resource://"+ getPackageName() +"/" + R.raw.fillings_class_1));
video.requestFocus();
video.setMediaController(new MediaController(this));
video.start();
}
#Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
//restore the relevant information
}
}
If you really need to prevent the activity from being restarted on an orientation change, you need to set the configChanges attribute for the Activity in the manifest to include orientation.

simple example how to insert audio file in android

i am trying to insert a audio file into the application which is not showing any kind of error but while am running the program then it is showing some kind of exception that to force close kind of dialog box and here is my code
This is my first activity where am trying to invoke the button into the second activity playing the audio file.
public class Audio extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b2=(Button)findViewById(R.id.b1);
b2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i1 =new Intent(Audio.this,Audio1.class);
startActivity(i1);
}
});
}
}
public class Audio1 extends Activity {
private MediaPlayer eMediaPlayer= new MediaPlayer();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audio);
eMediaPlayer=MediaPlayer.create(this, R.raw.ab);
eMediaPlayer.start();
}
}
audio is my xml file which is empty presently
R.raw.ab is the resource file which is 830kb audio file
you should call
eMediaPlayer.prepare();
before
eMediaPlayer.start();

Categories

Resources