Streaming MP4 problem - obvious answer? - android

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

Related

Play video stream using Vitamio library in android?

I'm using the library Vitamio to play rtsp live stream. I tried to run the demo videoview class play rtsp link as follows:
http://117.103.224.75:1935/live/definst/VTCHD3/VTCHD3_840x480_1200kbps.stream/playlist.m3u8
==> Result : it run but quality very bad, load videos very low and picture in video are not sharp and sound are not heard. I don't know what to do to make it run smooth and picture is sharp. Please help me this problem ! Thank very much !
this is my code :
private String path="http://117.103.224.75:1935/live/_definst_/VTCHD3/VTCHD3_840x480_1200kbps.stream/playlist.m3u8";
private ProgressDialog prodlg;
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
prodlg=new ProgressDialog(this);
prodlg.setIcon(R.drawable.ic_launcher);
prodlg.setMessage("wating...");
prodlg.show();
mVideoView = (VideoView) findViewById(R.id.surface_view);
if (path == "") {
// Tell the user to provide a media file URL/path.
Toast.makeText(VideoViewDemo.this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
return;
} else {
/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mVideoView.setBufferSize(2048);
mVideoView.requestFocus();
mVideoView.start();
mVideoView.setMediaController(new MediaController(this));
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
prodlg.dismiss();
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
}
}
I use android platforms 4.0 api 14 play demo :
this is my screen picture demo
If you want to use Vitamio library for displaying video etc, then first of all download Vitamio Library from here Free download Vitamio Library.
then include both "ZI" and "InitActivtiy" (which is inside the Vitamio lib) Library in your current project (right click project-->include library-->), then write this line of code
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
after Oncreate Method() like in my project.
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) //it will check the include library of Vitamio
return;
after that put this line of code in Androidmanifest.xml file
<!-- (((((( Vitamio Library including in manifest file )))))) -->
<activity android:name="io.vov.vitamio.activity.InitActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden"
android:launchMode="singleTop"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden"/>
Now its a time to display your video using VideoView etc.

Android play video button without videoview

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

Rtsp streaming using VideoView and MediaPlayer

I wana to develop android app that will play rtsp link from local server, but the tablet screen goes blank.... showing nothing
I had tried both VideoView and MediaPlayer classes.
Work well on youtube rtsp links with .3gp extension but not working on the above URL
Below is my code
public class WifiManagerActivity extends Activity {
private WifiManager customWifiManager;
private VideoView mu;
private String path;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
wifiSettings();
}
private void wifiSettings() {
mu = (VideoView) findViewById(R.id.ttl);
TextView notify = (TextView) findViewById(R.id.wifi_state);
customWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if(customWifiManager.isWifiEnabled()){
Toast.makeText(this, "Your wifi is On now enjoy " +
"live streaming", Toast.LENGTH_SHORT).show();
notify.setTextColor(Color.GREEN);
showVideo();
}else{
Toast.makeText(this, "Turn your Wifi On", Toast.LENGTH_SHORT).show();
customWifiManager.setWifiEnabled(true);
//two second wait here
showVideo();
}
}
private void showVideo() {
Authenticator.setDefault(new MyAuthenticater());
String path = "rtsp://192.168.1.155:554/3g";
mu.setVideoURI(Uri.parse(path));
mu.setMediaController(new MediaController(this));
mu.requestFocus();
mu.start();
}
}
There are multiple factors that can affect whether your stream is playing correctly or not:
check whether your stream is valid and playable (using for example separate instance of VLC)
if that works check logcat for any errors/warnings related to either RTSP connection or video stream itself. Look for tags like: MediaPlayer, ARTSPConnection, MyHandler, ASessionDescription, ACodec.
That should get you started.

Play Mp4 video from server android

I want to play video of mp4 format and size 4-5Mb from server in streaming mode.I am using sdk version 2.3,on emulator it
gives only sound but not any picture.
I also tested it on devices Samsung(android sdk ver 2.1) and LG optimus(android sdk ver 2.2)
and only get "cannot play video:sorry this video is not valid for streaming to this device" message.
I have searched on this but not getting any solution, if anybody have any solution please help me.Thanks in advance.
Here is my code:
public class ShowVideo extends Activity
{
private static ProgressDialog progressDialog;
public String video_url;
private MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoalbum);
progressDialog = ProgressDialog.show(ShowVideo.this, "", "Buffering video...", true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
video_url = "http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4";
try {
final VideoView videoView =(VideoView)findViewById(R.id.video_viewId);
mediaController = new MediaController(ShowVideo.this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse(video_url);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}catch(Exception e){
progressDialog.dismiss();
System.out.println("Video Play Error :"+e.getMessage());
}
}
You may try these urls (ends with .3gp):
http://daily3gp.com/vids/747.3gp
http://daily3gp/www/vids/juggling_while_on_unicycle.3gp
instead of .mp4 urls:
video_url = "http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4";
On emulator it is difficult to get video played, because it needs really fast computer. Try this link for emulator. Maybe you can get some discrete video view.
http://commonsware.com/misc/test2.3gp
Also in your real devices this link should work if your implementation is proper.
I assume your video using following link
"http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4
is not proper for safe streaming.
You should hint that video or play other hinted videos. I couldn't find any other solution for playing unhinted videos yet.
This link may help.
getting PVMFErrContentInvalidForProgressivePlayback error while playing mp4 files on samsung devices

Android: How can i play Video in the internal MediaPlayer from a Resource, Can anyone Help?

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.

Categories

Resources