I have an mp3 file in a shortened URL:
http://services.xyz.net/2_4/download?file=l9G0qe5b%2fiMDXhIGuvMhHg%3d&token=c371ae3c-ed65-4991-bbdc-bd2e5333116e
The file is not getting played if I use the shortened URL. I am getting IOExeception in MediaPlayer.prepare() but if I put the file in public server and try to play using the fully qualified URL it plays. But the Blackberry and the iPhone are able to play the same song using the same shortened URL. I have a requirement to use the shortened URL. How to stream mp3 file and play for this type of shortened URL? If I put that shortend url in device browser then the file is getting downloaded from that place. This url is not redirecting to any other url. Also I have tested the same code works for some other shortened URL from the same server.
if(player!= null){
player.stop();
player.reset();
player.release();
player = null;
}
String url ="http://services.xyz.net/2_4/download?file=l9G0qe5b%2fiMDXhIGuvMhHg%3d&token=c371ae3c-ed65-4991-bbdc-bd2e5333116e";//for this not working
/*
String url = = http://203.123.181.194/downloads/sunil/Try.mp3;//here its working
*/
System.out.println("....URL...."+url);
player = new MediaPlayer();
player.setDataSource(url);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.prepare();
player.start();
Related
I want to play android motion photo with media player. But I don't want to use mediaPlayer.setDataSource(fileDescriptor, offset, length). Because I am not getting offset for Huawei device's Motion Photo. How can I get the offset for all device's motion photo or is it possible to use mediaPlayer.setDataSource(path, headers) instead? I have heard about a header called 'ftypmp42'. How to use this in this case?
You may refer this ,
i have Done something I may Tell you that may help you to Find the Offset and play
XmpUtil xmp = new XmpUtil();
XMPMeta meta = xmp.extractOrCreateXMPMeta(jpegFile.getAbsolutePath());
haveVideoValue = meta.getProperty("http://ns.google.com/photos/1.0/camera/","GCamera:MicroVideo");
offset=meta.getProperty("http://ns.google.com/photos/1.0/camera/","GCamera:MicroVideoOffset");
//To play the Video with Media player
FileInputStream inputStream = new FileInputStream(filePath);
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(inputStream.getFD(), finalJpegFile.length() - Long.valueOf(finalOffset1), Long.valueOf(finalOffset1));
mp.prepare();
inputStream.close();
mp.setDisplay(surface.getHolder());
mp.setLooping(true);
mp.start();
Credit :- https://medium.com/android-news/working-with-motion-photos-da0aa49b50c
In my application I want to play server m3u file directly with out downloading the file. For this i am using bellow code
String url = "http://........"; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();`enter code here`
But did not work.
this is the server url file
http://stream.abacast.net/playlist/mwfmadison-wrisfmmp3-ibc3.m3u.
So can any one please how to do this
I am trying to connect my android application with FTP Server which is broadcasting multiple streams using Dynamic Http Streaming at different bit rates.Flash Messaging Server(FMS) is using H.264 codec to broadcast video in flv format.On client side(Android) I am getting f4m(manifest (xml) file)) having diffrent streams.
I am unable to use the f4m file to fetch video in android from FMS.
String url = "http://d2233avv69kunu.cloudfront.net/hds-live/livepkgr/_definst_/liveevent/livestream.f4m";
Uri uri = Uri.parse(url);
// videoView.setVideoURI(uri);
videoView.setVideoPath(str);
MediaController mc = new MediaController(this);
//VMRuntime.getRuntime().setMinimumHeapSize(40);
mc.setAnchorView(videoView);
videoView.setMediaController(mc);
System.out.println("Max Memory - "+java.lang.Runtime.getRuntime().maxMemory());
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
videoView.start();
}
});
In above code I am trying to run video in Video View component by passing link of f4m file.
Flash encoder convert video into 3 file formats as listed below
.f4m (manifest files) - Bootstrap Info,Metadata, Bitrate, Flash Access license Server location
.f4f (fragment files) - extends the F4V format,MP4 fragment std
.f4x (index files) - binary
Kindly provide solution to play video on different android devices via Http Streaming in android.
Thanks in advance.
1) You have left something out of your code. What is str that you are passing to setVideoPath? (this is somewhat irrelevant, though...)
2) The MediaPlayer (and thereby VideoView) cannot play Flash video at all. It's simply not supported. It definitely won't understand an XML file, either, so passing it the f4m file is pointless.
So I created a directory on the internal storage like so:
File mediadir = getDir("tvr", Context.MODE_PRIVATE);
Then I download files from a server and save them inside the directory like this:
URL url = new URL(urlString);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream is = url.openStream();
Log.d("DOWNLOAD NAME",name);
FileOutputStream fos = new FileOutputStream(mediadir+name);
etc
Then files are saved successfully, then next I want to play them like this:
String path = filelist[playListIndex].getAbsolutePath();
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setOnCompletionListener(this);
videoView.setVideoPath(path);
videoView.start();
where path is :
/data/data/com.mypackage/tvr/video.mp4
The file does not want to play with this error:
02-20 15:57:21.447: E/MediaPlayer(24143): error (1, -2147483648)
And on the device a message pops up : Cannot play video, Sorry this video cannot be player.
Is this a issue with rights or what? If it is, I was thinking because I created them, I have the rights to them?
CommonsWare has a good example on how to use the VideoView. Here is a link to someone who had a similar issue with video not wanting to play:
Playing a video in VideoView in Android
Also here is a video class of his example that I found useful when learning how to incorporate the VideoView:
https://github.com/commonsguy/cw-advandroid/blob/master/Media/Video/src/com/commonsware/android/video/VideoDemo.java hope this helps.
I would also make sure that you have the permission settings in your manifest set:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
The problem might be with the video encoding. Android FROYO and Gingerbread doesn't support H264 formats other than "Baseline" H264. So if your video is Mp4 & H264 encoded make sure its "AVC baseline" encoded. Use some tools like "Media info" in windows/Linux and check your video encoding. Convert the video to Baseline if possible.
An alternative workaround is to skip the Videoview and use a video play intent and redirect the playback to an app. User will be prompted to pick a player to handle the playback. Obviously if the video view cant play the file, the default player also wont be able to handle the file. you can choose some other installed player like Mx-Player which will stream the file perfectly.
I want to play video content from HttpResponse object. The content is downloading from a streaming sever.
My requirement is to create a HTTP POST request to the server. Request contains the URL of video, username and password of the user for authentication purpose.
I wish to know how can we create a HTTP POST request and play/download the video.
Kindly provide some hints, steps/code to proceed.
Thanks,
I am not 100% sure, but I think that you can't stream most of the video due to the way the format stores the meta data of the video. That's why you tube has to convert your video files instead of just showing them in any format.
There are protocols that encapsulate this metadata and allows you to stream any video (that's what youtube mobile does). You should take a look at RTSP: http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol
If you use an rtsp link in a videoView it should stream the video flawlessly. The point is that your problem is server and not client related.
As an exercise you could grab an rtsp link from m.youtube.com and just pass to a videoView using setVideoPath and it should work.
If can't change the server implementation then you probably them I guess your solutions are:
1) Download and decode the video yourself, you would have to handle all the metadata and ensure that the video does work though. You could, theoretically, compile ffmpeg for android to help you with that, but I couldn't compile it to android with the network option on. That is a lot of work.
2) Write your own implementation of RTSP or other streaming protocol. Download the video in a thread and them create a local server in the device to stream that video file to a videoView instance. I actually have this working on an app. Android doesn't support the specific protocol that the client's servers use and I had to get it working. It took me a full month to do this. I can't post any example code because it's all the client's, but I could give you some further info on this if you are interested.
Either way, if you can't change the server/format of the video then you should prepare for a whole lot of work.
check the below code for showing a url http or rtsp in Video View.
Now before invoking your videoview .. just get
public class VideoViewDemo extends Activity {
/**
* TODO: Set the path variable to a streaming video URL or a local media
* file path.
*/
private String path = "";
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
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();
} else {
/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
}
Now since your requirements are different first make http post request to your server ... get the desired input stream.. write that stream as mp4 to your local file system. then you can use below code to play content
// this can be path on file system
String path="/adf.mp4" ;
public void playVideo() {
MediaController mediaController = new MediaController(this);
mediaController.setMediaPlayer(videoView);
videoView.setVideoPath(path);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
mediaController.show();
I tried this and it worked for me :D no rtsp no nothing, just a url with a mp4 video and it played!
public class VideoActivity extends Activity {
public static final String KEY = "video_id";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fotogaleria_video);
Intent i = getIntent();
if(i.hasExtra(KEY)){
String url = "https://sites.google.com/site/tempmp4download/bnm.mp4";
VideoView vv = (VideoView)findViewById(R.id.fotogaleria_video);
// vv.setVideoPath(url);
vv.setVideoURI(Uri.parse(url));
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();
}
}
}
Look into following links
http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/
http://w3mentor.com/learn/java/android-development/android-http-services/performa-a-http-post-request-with-the-httpclient-in-android/
For streaming, I think you have to download the full file, and then show it in the video player.