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.
Related
I want my video activity to go fullscreen when the video starts, but it's not happening. Here are some screenshots and the code that runs this activity.:
public class InfoLentes extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.infolentes);
}
public void sendMessage(View view) {
setContentView(R.layout.fullscreen);
VideoView VideoView = new VideoView(this);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
VideoView.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.eyeprotect);
VideoView.setVideoURI(video);
setContentView(VideoView);
VideoView.start();
}
}
And this is my fullscreem.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="#+id/VideoViewfull"
android:layout_width="match_parent"
android:layout_height="match_parent">
</VideoView>
</FrameLayout>
And Screenshots of whats happening.:
What am I doing wrong?
EDIT:
So Using #Sheetal Kumar Maurya answer, I created another activity and used the android:theme="#style/AppTheme.NoActionBar" on the manifest, the result is better, but still not really fullscreen.:
Create a VideoPlayer activity with NoActionbar theme.
<activity
android:name=".VideoPlayerActivity"
android:theme="#style/AppTheme.NoActionBar" />
In onCreate section add following:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Now use this activity as a player for full screen and enjoy.
So I finally, after a long time of searching, found the perfect solution for my problem.
Using the answer here on this post from #Hamiseixas, I did the following.:
Edited Gradle, and synced:
compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.2'
repositories {
mavenCentral()
}
Instead of a videoview, I used the new compiled package on my fullscreen.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent">
<com.github.rtoshiro.view.video.FullscreenVideoLayout
android:id="#+id/videoview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.github.rtoshiro.view.video.FullscreenVideoLayout>
</RelativeLayout>
And when I press the intent button to take me to the video file I want to play, this is the activity that playes it.:
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.github.rtoshiro.view.video.FullscreenVideoLayout;
import java.io.IOException;
public class VideoTest extends AppCompatActivity {
FullscreenVideoLayout videoLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullscreen);
videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
videoLayout.setActivity(this);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.eyeprotect);
try {
videoLayout.setVideoURI(video);
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}
It was that simple =D
It's all better documented here, a huge thanks to that post, and to the creator of FullscreenVideoView, Toshiro
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";
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();
}
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 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();
}
}