I am creating video playing app from Youtube. I have extracted Video Data using gdata API and got 3gp url for format 1,6. This i got extracted from Media:Group --> Media:content element.
My Device Info Android 4.0.3 and Model Micromax P350.
These video is working in VLC Player but not in VideoView enter code here in my app. Here is my code:
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_height="fill_parent"
android:paddingLeft="2px"
android:paddingRight="2px"
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddi`enter code here`ngTop="2px"
android:paddingBottom="2px"
android:layout_width="fill_parent"
android:orientation="vertical">
<VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="#+id/VideoView" />
</LinearLayout>
MainActivity.java
package com.example.firstapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView)findViewById(R.id.VideoView);
//MediaController mediaController = new MediaController(this);
// mediaController.setAnchorView(videoView);
//videoView.setMediaController(mediaController);
videoView.setVideoPath("rtsp://v1.cache8.c.youtube.com/CiILENy73wIaGQneb1Sj_PGnoRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp");
videoView.start();
}
}
Must be your video is not in one of the supported formats:
http://developer.android.com/guide/appendix/media-formats.html
//play rtsp stream
private void PlayRtspStream(String rtspUrl){
videoView.setVideoURI(Uri.parse(rtspUrl));
videoView.requestFocus();
videoView.start();
}
Related
I am using VideoView to play video from url. When I run app it gives error Can't play this video with below msg in logcat
Couldn't open file on client side; trying server side:java.io.FileNotFoundException: No content provider:aklearningsolutions.com/video/Nursery%20Rhymes.mp4
Unable to open content: aklearningsolutions.com/video/Nursery%20Rhymes.mp4
java.io.IOException: setDataSource failed.
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1095)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1069)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1023)
below is my activity file
package com.dp.videostore.Activity;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.TextureView;
import android.widget.MediaController;
import android.widget.VideoView;
import com.dp.videostore.R;
public class PlayerActivity extends AppCompatActivity {
VideoView videoView;
String url = "aklearningsolutions.com/video/Nursery Rhymes.mp4";
MediaController mc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
videoView = (VideoView)findViewById(R.id.video_view);
try {
mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
Uri link = Uri.parse(url.replace(" ","%20"));
videoView.setVideoURI(link);
videoView.requestFocus();
videoView.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Below is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.dp.videostore.Activity.PlayerActivity">
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/video_view"/>
</RelativeLayout>
When i hit video link in web browser, video play very well in browser
Try putting the protocol into your URL. As it is, Android thinks you are using a ContentProvider
String url = "http://aklearningsolutions.com/video/Nursery Rhymes.mp4";
Anyone help me. I am preparing application to integrate video into it. Kept video in res/raw folder. Video format .mp4. Working api-level-21. It is working on android devices for android version 2.2 but not on 4+.
Here is my code:
java:
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.MediaController;
import android.widget.VideoView;
public class Gift extends ActionBarActivity {
MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.gift);
VideoView myVideoView = (VideoView) findViewById(R.id.videoView);
Uri uri= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sidbday);
mediaController = new MediaController(this);
myVideoView.setMediaController(mediaController);
myVideoView.setVideoURI(uri);
myVideoView.start();
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<VideoView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/videoView"/>
</RelativeLayout>
This message is shown when framework is not ready to play video yet. You can start your video after onPrepared method is called:
instead of myVideoView.start(); use
video.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
myVideoView.start();
}
});
EDIT
I didn't notice that it's an old topic but maybe it hepls someone.
I am trying to play youtube video within video view but getting error(can't play this video) all the time(on device as well as on emulator too). Please help me with this problem.
Thanks in advance.
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;
public class AndroidVideoView extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView myVideoView = (VideoView) findViewById(R.id.videoview);
String viewSource = "rtsp://v2.cache8.c.youtube.com/CjYLENy73wIaLQndUnGVjs340xMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYJP8mrqSz625UAw=/0/0/0/video.3gp";
myVideoView.setVideoURI(Uri.parse(viewSource));
myVideoView.requestFocus();
myVideoView.start();
}
}
1) Videos will not buffer on emulator because it is virtual device. In-order stream video you should use real device
2) you must provide this permission because with out internet connection we will not able to connect with YouTube server
<uses-permission android:name="android.permission.INTERNET" />
3)Please validate your RTSP link. Given below is my rtsp link for my YouTube video
"rtsp://v1.cache6.c.youtube.com/CiILENy73wIaGQnCikhfRzTDsBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
To generate rtsp link Use this
http://gdata.youtube.com/feeds/mobile/videos/"+Video Id+"
In my case Video Id is sMM0R19IisI
My Code
public class MainActivity extends Activity {
String SrcPath = "rtsp://v1.cache6.c.youtube.com/CiILENy73wIaGQnCikhfRzTDsBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";//"rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoURI(Uri.parse(SrcPath));
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
}
LAYOUT XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="#+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I am using a VideoView to play Mp4 video. There are buttons in the screen and on the click event I need to change the video of the VideoView and play. I want this transition to be as smooth as possible. This is the code I was using in the button onclick handler.
Uri uri = Uri.parse("android.resource://"+getPackageName() + "/"+R.raw.myvideo);
mainVideoView.setVideoURI(uri);
mainVideoView.requestFocus();
mainVideoView.start();
I was testing this on my phone with Andorid 4, everything worked fine. But when I tested it in a phone with Android 2.2, I was shocked to see on click of the button the videoview part of the screen becomes black for a second and the new video starts. I cant afford that delay in my application.
Try this code
This is a java code
package com.android.video;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoActivity extends Activity {
/** Called when the activity is first created. */
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
//videoView.setVideoURI(Uri.parse("http://www.mediafire.com/?trc33d4yma3rkv3.mp4"));
videoView.setVideoPath("/sdcard/movie.mp4");
videoView.requestFocus();
videoView.start();
}
}
This is main.xml
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<VideoView android:id="#+id/videoView" android:layout_width="300dp" android:layout_height="300dp" />
</LinearLayout>
This is manifest file
<uses-permission android:name="android.permission.INTERNET" />
I have code for simple audio player on android. But it is not working for videos. Please guide me to write a simple video player.
The code of audio player is
package com.example.helloplayer;
public class HelloPlayer extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaPlayer mp = MediaPlayer.create(this, R.raw.file);
mp.start();
}
}
For making a video player you will have to make use of video view. a sample is shown below
Layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView android:id="#+id/videoView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"/>
</LinearLayout>
Here i am playing a video stored in "resource/raw" folder , "one" is the name of video file,you can replace it with name of your video file .also make sure that you are going to play an android supported video format
VideoplayerActivitvity
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class VideoplayerActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView =(VideoView)findViewById(R.id.videoView);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.one);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
}