I have a simple button, and I wish to play an URL video buy clicking on this button but without a videoView.
So if I click on the button , the phone will ask which internal player I'll choose to play the video.
Here I was using a videoView that was playing the video inside the window of my application but I want it outside :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
video = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
Uri chemin = Uri.parse("http://commonsware.com/misc/test2.3gp");
video.setVideoURI(chemin);
video.start();
Thank you,
so here's the code :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
boutonVideo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent in;
if (v.getId() == R.id.boutonVideo) {
in = new Intent(Intent.ACTION_VIEW, Uri
.parse(urlBandeAnnonce));
startActivity(in);
}
}
});
But it return me an error when I decide to stop the video and return to my activity.
Here is the AndroidRunTime Error :
java.lang.RuntimeException: Unable to start activity
ComponentInfo{Activity}: java.lang.NullPointerException
09-30 15:20:16.449: E/AndroidRuntime(2301):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
Solved
So I add finish(); and the error disappear.
Use an Intent with ACTION_VIEW along with the URI to the movie you want to play:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
startActivity(intent);
where movieUrl is a string containing the path to the movie.
This may or may not work with internet streams. Haven't tried it with those personally.
Have you looked to Android Api examples
if you have installed the samples on your pc it is located at (for windows systems)
C:\Program Files\Android\android-sdk\samples\android-16\ApiDemos\src\com\example\android\apis\media
Related
I have asked what is the code that sends a link from the application that I'm making to the vimeo application; it opens vimeo application but not the video specified in the link, does anybody knows how?
vimeo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
Intent browserIntent = null;
PackageManager pmi = getPackageManager();
browserIntent = pmi.getLaunchIntentForPackage("com.vimeo.android.videoapp");
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
catch(Exception e){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
}
});
I answered your other question with this solution. But I believe it will fix this issue as well since our vimeo-deeplink library accommodates opening our specific application.
You could include it with gradle:
compile 'com.vimeo.android.deeplink:vimeo-deeplink:1.0.0'
And then deeplink to your video with this method:
boolean handled = VimeoDeeplink.showVideoWithUri(Context context, String videoUri)
Where videoUri is equal to /videos/83178705.
By doing this below, it will reset all your app preference
Go to Settings->Apps, choose from menu Reset app preferences and confirm Reset apps.
After that,
choose it in Settings->Apps and press Clear defaults button for vimeo app
Now try to open that video link(vimeo link) again. Now it'll ask you to select which app to use. Then select your vimeo app as default
I am trying to autoplay youtube videos on android, which evry time i play video must press play button to play and that is a bad experince for the user, so i try many method but it dosnt work
so please guys help me ,thanks for advise
and this is a pieace of my code
#Override
public void onClick(View v) {
Intent intent = null;
intent=YouTubeStandalonePlayer.createVideoIntent(activity,DeveloperKey.DEVELOPER_KEY, VIDEO_ID);
activity.startActivity(intent);
}
autoplay = true;
lightboxMode = false;
intent = YouTubeStandalonePlayer.createVideoIntent(
this, YOUR_DEVELOPER_KEY, VIDEO_ID, startTimeMillis, autoplay, lightboxMode);
This works for me and can be found in youtube samples.
Documentation:
createVideoIntent(Activity activity, String developerKey, String videoId, int timeMillis, boolean autoplay, boolean lightboxMode)
Implementation example:
intent = YouTubeStandalonePlayer.createVideoIntent(this, DeveloperKey.DEVELOPER_KEY, VIDEO_ID, 0, true, false);
You need to pass true for autoplay parameter
I want to play a streaming video in android from a website.
For example, I want to play the streaming video from this url: http://florotv.com/canal2.html
Using URL Helper, I have been able to capture the rtmp URL that it's
rtmp://198.144.153.139:443/kuyo<playpath>ver44?id=acf6f5271f8ce567ed6c8737ce85a044&pid=32342e3136362e37332e323139 <swfUrl>http://yukons.net/yplay2.swf <pageUrl>http://yukons.net/embed/37363635373233343334/eeff74c57593ca38defc902fa6d88005/600/400
Now that I have this URL, I wanna know if it's possible to play the video in android.
I have tried this but it doesn't work because I don't know how to set the swfUrl, pageUrl.....
private static final String MOVIE_URL="rtmp://198.144.153.139:443/kuyo";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(MOVIE_URL);
intent.setData(data);
startActivity(intent);
Thanks in advance....
Add below code into your Activity.java file.
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoPlayer);
try {
String link="http://videocloud/video.mp4";
VideoView videoView = (VideoView) findViewById(R.id.myVideoView);
final ProgressBar pbLoading = (ProgressBar) findViewById(R.id.pbVideoLoading);
pbLoading.setVisibility(View.VISIBLE);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
pbLoading.setVisibility(View.GONE);
}
});
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}
}
If you don't need MediaController set it to null videoView.setMediaController(null)
I don't think it's enough to just create an intent, you also have to create a context for the video to be played : Like a VideoView object.
The link below has a suggestion for this pattern :
http://androidcodeexamples.blogspot.sg/2011/08/how-to-play-mp4-video-in-android-using.html
Essentially a MediaController object is created with the VideoView object. Then the VideoView is used to start the operation once the URI is set.
Edit :
Probably the main problem though is that your URL contains POST parameters and isn't exactly a unique identifier of a resource (in this case a video file).
The 'swfUrl' and 'pageUrl' parameters are most likely unique to the server that's providing you the page.
You can use Vitamio library for android, where you can set the swfUrl and pageUrl.
Here is a tutorial for it.
I'm a Flash developer by trade, have recently made the jump into Android as the company I work for are moving into apps. I've made a video gallery based on an XML feed, it all works fine until I have to play the movie itself, at which point I get:
Unable to play video. Invalid streaming data.
My gallery items fire up another activity with the .mp4 link as an extra:
public class Video_play extends Activity implements View.OnClickListener {
String vLink;
Uri vid;
VideoView vv;
MediaPlayer mp;
SurfaceHolder holder;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//Hide app title
Bundle extras = getIntent().getExtras();
if (extras != null) {
vLink = extras.getString("video");
vid = Uri.parse(vLink);
}
setContentView(R.layout.vidplay_layout);
vv = (VideoView)findViewById(R.id.vid_fscreen);
Log.i("Video link is: ",vid+"");
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(vv);
vv.setMediaController(mediaController);
vv.setVideoURI(vid);
vv.start();
}
public void onClick(View v) {
}
}
I've been looking all afternoon and I can't find any straightforward advice on what I'm doing wrong. Any help would be absolutely life-saving, thanks in advance.
What version of Android are you testing it on? HTTP progressive streaming for MP4 video was not fully supported until Android 2.2.
For streaming playback on earlier Android versions you can usually work around this by using post-encoding software like MP4Box to add "hint tracks" to the file:
MP4Box -hint <filename>
http://www.videohelp.com/tools/mp4box
I am trying to play a mp4 video from the resource within the app, either res/raw or assets, but i am having no luck, nor can i find any tutorials or solutions that work anywhere, hoping someone hear can provide the answer.
Code below that i thought would work but doesnt, please show me how?
Thanks
Lucy
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
final Button button = (Button) findViewById(R.id.play);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Uri uri = Uri.parse("android.resource://com.video.play.test/" + R.raw.test2);
Intent intent=new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/mp4");
startActivity(intent);
}
});
}
Please check this answer on that subject:
https://groups.google.com/group/android-developers/browse_thread/thread/9a934f3aa2e4256/577d991b0f94aaf2?hl=hr&lnk=gst&q=play+video+resources#577d991b0f94aaf2
What I have managed was to play video from resources in my application (SufraceView in my layout). Another approach is (as suggested in the link) to copy video to SD card and easily play it from there using internal (system) MediaPlayer.