How to set Media Player (Videoview) on Button click?

All your problems with Audio, Video and Images.

How to set Media Player (Videoview) on Button click?

Postby Radjinn » Thu Jun 02, 2011 10:05 am

First of all i want to say this Forum ist great and i hope you will find a solution!

I write a app that can laod 3gp videos from Url and play it whit build in MediaPlayer from Android, my question ist how i can load the hole Mediaplayer whit url link whit a button click from a singel activity?
Because now i load the Video whit a simple intent open activity button click, witch means i need a activity for each Video, and this woud be to many!

Here my SourceCode:
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class videoact extends Activity implements OnPreparedListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview);

MediaController mc = new MediaController(this);
VideoView vv = (VideoView)findViewById(R.id.view1);
try
{
Uri ur = Uri.parse("rtsp://v4.cache4.c.youtube.com/CjgLENy73wIaLwkHCCLABs2fehMYJCAkFEIJbXYtZ29vZ2xlSARSB3JlbGF0ZWRg7e7u0PeUj8hMDA==/0/0/0/video.3gp");
vv.setVideoURI(ur);
vv.setMediaController(mc);
vv.requestFocus();
vv.start();
mc.show();
}
catch(Exception e)
{
System.out.print(e.getMessage() + "error");
}

}

public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.start();
}

}
Radjinn
Freshman
Freshman
 
Posts: 4
Joined: Thu Apr 07, 2011 7:46 pm

Top

Re: How to set Media Player (Videoview) on Button click?

Postby raj_J2ME » Thu Jun 02, 2011 10:54 am

AFA I have understand your need is that you want to play the video where you should have all the videos listing and hitting a particular button lets say play, the selected video should start.

before replying anything I wanna clear your requirement.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: How to set Media Player (Videoview) on Button click?

Postby Radjinn » Thu Jun 02, 2011 11:31 am

raj thanks for the quick reply,
your right what i need to do is i have a activity( MainActivity) were i load a layout in this layout i have the covers of different movies the covers are buttons!
so if i pres the cover the media player shoud start play the code i write before, my problem is the code i write is in a another activity lets call him (Movie1), if i do it this way i have to create for each movie one activity and this is to much i think, lets say it woud be more than 40 activitys, if you say 40 activitys is noch much than i have no problem, ore just tell me hove to say my activity (MainAcitivity) for example on button click open video from url file whitout open Movie1 actiivity!

I think i have to create a blank MediaPlayer activity where i can say load by button click x this url whit my MediaPlayer activity but i dont now how?

I hope this was more clear!!!
Radjinn
Freshman
Freshman
 
Posts: 4
Joined: Thu Apr 07, 2011 7:46 pm

Re: How to set Media Player (Videoview) on Button click?

Postby raj_J2ME » Thu Jun 02, 2011 12:25 pm

You can do it in many ways : the simpler one could be -

Make some ListView of all the videos and let the user select either of them and give play button there so that the video can be played. As soon as you select the play button, you take the absolute path of the video and let the device media player play the video for you. Lets device's player is on the activity1, then you can reuse the same and just pass the selected video to the player.

How this sounds to you?
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: How to set Media Player (Videoview) on Button click?

Postby Radjinn » Thu Jun 02, 2011 12:50 pm

Sounds great but there is just one problem

How i shod say the "Play" button shoud grab the url for this video and play it on the "MediaPlayerActivity"
can you give me an example how to set this
one for play button and
one for the mediaplayer activity whitch i have to tould if play is pressed play the link he ist submit you!

thant woud be great help!
Radjinn
Freshman
Freshman
 
Posts: 4
Joined: Thu Apr 07, 2011 7:46 pm

Re: How to set Media Player (Videoview) on Button click?

Postby raj_J2ME » Thu Jun 02, 2011 1:06 pm

BTW I dont have any ready made example, however let me explained in much more details:

1. make the list of all available videos
2. Add play button to this listview
3. when you wanna play any video, out of the list, you will go to that in list
4. As soon as use said, play video 12th, then you have to take the absolute path (if the video is inside the res) and pass the same to the player and start the player.

5. from the player activity you can come back to the listing of the videos.

I hope I am clear and it sound feasible to implement.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Top

Re: How to set Media Player (Videoview) on Button click?

Postby Radjinn » Thu Jun 02, 2011 1:37 pm

First of all thanks for your help!
I will studie what you say and try to find examples for it!

I will post my solutions for your thougts!
Radjinn
Freshman
Freshman
 
Posts: 4
Joined: Thu Apr 07, 2011 7:46 pm

Re: How to set Media Player (Videoview) on Button click?

Postby whytopersist » Mon Sep 05, 2011 10:58 am

Hi,I'm new here.This forum is very interesting that I like it very much.

Coach outlet | Coach Handbags | Coach Bags
whytopersist
Freshman
Freshman
 
Posts: 6
Joined: Mon Sep 05, 2011 10:37 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests