Below is my code and I'm gonna integrate with the application. My problem is when the button clicked video recorder invoked and video recoded smoothly but I want to get the response from the camera when the video recording is done every time.
public class AndroidVideoActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnVideoRecorder = (Button)findViewById(R.id.buttonClick);
btnVideoRecorder.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.VIDEO_CAMERA");
startActivity(intent);
}
});
}
}
Can someone please guide me.
Thanks for your time in advance.
Try changing
startActivity(intent);
to
startActivityForResult(intent);
Then when the video is done recordng, it will return to your app and you will be able to do something with the video
Related
I have an Android app. I created a class for the media menu. When I return from the media menu to the main activity, the sound works, but if I return to the media menu again, the sound does not cut off. Moreover, if I then press the pause button, the application crashes!
How can I solve this issue? I have thought of a lot of solutions except that I cannot create a destroy function because it is not present in the options.
Here is my code:
play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (mdp == null) {
mdp = MediaPlayer.create(context, d.getsound());
mdp.start();
} else {
mdp.pause();
mdp = MediaPlayer.create(context, d.getsound());
mdp.start();
}
}
});
Give this a shot my friend
#Override
public void onPause(){
super.onPause();
mdp.stop();
mdp.release();
}
Using the following code I can play a video on android in a new Activity. I would however like to preload the video (during a loading screen) and then show it when it is fully loaded. Is it possible to perhaps somehow trigger the activity to show later? In theory It would also be ok to not use a different activity.
public class VideoPlayer extends Activity implements OnCompletionListener,OnPreparedListener
{
private VideoView mVV;
#Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.videoplayer);
String url = getIntent().getStringExtra("url");
if(url == null)
finish();
mVV = (VideoView)findViewById(R.id.myvideoview);
mVV.setOnCompletionListener(this);
mVV.setOnPreparedListener(this);
mVV.setVideoURI(Uri.parse(url));
mVV.start();
}
public void stopPlaying() {
mVV.stopPlayback();
this.finish();
}
#Override
public void onCompletion(MediaPlayer mp) {
finish();
}
#Override
public void onPrepared(MediaPlayer mp) {
}
}
from my main activity:
private void playVideo(String url) {
Intent videoPlaybackActivity = new Intent(this, VideoPlayer.class);
videoPlaybackActivity.putExtra("url", url);
startActivity(videoPlaybackActivity);
}
I presume I can use the onPrepared function, but I'm not sure how to do the activity triggering to show the activity later.
http://developer.android.com/reference/android/widget/VideoView.htmlHere are the methods for the VideoView. So there is indeed a:
setOnPreparedListener(MediaPlayer.OnPreparedListener l)
Probably the best way is to use fragments in the activity and show the fragment in the activity where the mVV = (VideoView)findViewById(R.id.myvideoview); is declared when the onprepared is called.
Or hide and show the view in the activity. (using fragments is probably nicer).
Think that will work and that that is what you wanted?
I'm using a small 2 second sound effect attached to a button. When clicked, the sound effect plays and the user is taking to the next activity. The function I created is outside onCreate and uses Intent to send the user to the next activity. When I add the mp variables I get an error saying there's a problem with playGame(). What is causing the MediaPlayer to not play when it's placed in this function? Eclipse suggests changing mp.create() to MediaPlayer.create but that doesn't fix the issue.
public class SplashScreenActivity extends ActionBarActivity {
public MediaPlayer mp;
public void playGame(View view) {
mp.create(this, R.raw.bulletricochet);
mp.start();
// Do something in response to button
Intent intent = new Intent(this, QuizActivity.class);
startActivity(intent);
}
public void playRules(View view) {
Intent intentR = new Intent(this, RulesActivity.class);
startActivity(intentR);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
}}
Your mp object is null and yet you are calling create method on it.
To create a MediaPlayer object use MediaPlayer.create. You say you tried it but probably didn't assign the return value to your mp variable.
mp = MediaPlayer.create(this, R.raw.bulletricochet);
i am new in this space i am working with mini app.
i have Animal images in Main template and want when click for example Dog image it must switch another page and there will be dog description and image gallery.
so i need to know how to create multiple pages and redirect it.
this is my app.
Thanks ...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//////////////////////// Dog
Button button3 = (Button)this.findViewById(R.id.button3);
final MediaPlayer dog = MediaPlayer.create(this, R.raw.dog);
button3.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// If the music is playing
if(dog.isPlaying() == true)
// Pause the music player
dog.pause();
// If it's not playing
else
// Resume the music player
dog.start();
}
});
You must create differents activity for different pages.
And use Intent to change page.
Example :
Intent intent = new Intent(MainActivy.this, OtherActivity.class);
startActivity(intent);
I want to start camera and also to automatically start recording just by clicking an app in android. I have the code to start the camera but I do not know how to start auto capture of the video. Please help.
the code I have for launching camera-
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c1_main);
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
StartActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY);
}
I found about view.performclick but do not know how to use for camera
Use MediaRecorder for this purpose. Though it will require more work but will give you much more control. Follow this link http://android-er.blogspot.tw/2011/04/start-video-recording-using.html. Since you don't reuire any button click for recording, keep a delay before starting the camera. Do it like this
myButton.setPressed(true); //you won't click the button
myButton.invalidate();
myButton.postDelayed(new Runnable() {
public void run() {
myButton.setPressed(false);
myButton.invalidate();
releaseCamera(); //release camera from preview before MediaRecorder starts
if(!prepareMediaRecorder()){
Toast.makeText(AndroidVideoCapture.this,"could not prepare MediaRecorder",Toast.LENGTH_LONG).show();
finish();
}
mediaRecorder.start();
}
},5000); //causes delay of 5 seconds befor recording starts
Ok, Make following, changes in your code.
Button play;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c1_main);
play = findViewById ( R.id.btnPlay ); // assuming you have this button in your .xml file.
play.setOnClickListener ( new OnClickListener()
{
#Override
public void onClick ( View view )
{
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
StartActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY);
}
});
}