Can we play flv stream videos in Android without using WebView, it's too slow? I mean play .flv video directly from url. Any ideas? VideoView now work with the .flv link.
I got it to work using this code. You can play it local from your device or stream it from online. You have to drag an instance of the FLV COMPONENT in your movie and then just delete it from the stage to it remains in your library.
var myVideo:FLVPlayback = new FLVPlayback();
myVideo.source = "content/video/BeauIntro.flv"; // CHANGE THIS TO YOUR FLV
myVideo.autoPlay = true;
// I am choosing to load the flv into an empty movie but you don't have to.
var my_mc:MovieClip = new MovieClip();
addChild(my_mc);
/// These are important because it can mess up position with out it.
myVideo.align = StageAlign.TOP_LEFT;
myVideo.scaleMode = VideoScaleMode.EXACT_FIT;
// Setting the video to the screen size of device
myVideo.width = stage.stageWidth;
myVideo.height = stage.stageHeight;
// Adding my FLV into my empty movie.
my_mc.addChild(myVideo);
//Setting the empty Movie Clip for the video to the screen size of device
my_mc.width = stage.stageHeight;
my_mc.height = stage.stageHeight;
/// This will run when the video stops
myVideo.addEventListener(fl.video.VideoEvent.COMPLETE, VideoStopped);
function VideoStopped(e:Event):void
{
myVideo.stop();
myVideo.visible = false; /// I wanted it to not be seen after playing.
trace("stopped");
myVideo.removeEventListener(fl.video.VideoEvent.COMPLETE, VideoStopped);
}
try this:
String url=your url here;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "flv-application/octet-stream");
startActivity(intent);
Related
Using the following code I was able to play back a udp stream (mpeg2 ts) which has 3 tracks (video, audio and dvb subtitles), but I am trying to retrieve the subtitle track and display it, i couldn't find any clear documentation on how to do it.
// Create LibVLC
ArrayList<String> options = new ArrayList<String>();
options.add("-vvv"); // verbosity
options.add("--autoscale");
libvlc = new LibVLC(this, options);
holder.setKeepScreenOn(true);
// Creating media player
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setAspectRatio("16:9");
mMediaPlayer.setEventListener(mPlayerListener);
// Seting up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurface);
if (mSubtitlesSurface != null)
vout.setSubtitlesView(mSubtitlesSurface);
vout.setWindowSize(1920,1080);
vout.addCallback(this);
vout.attachViews();
Media m = new Media(libvlc, Uri.parse(media));
mMediaPlayer.setMedia(m);
mMediaPlayer.play();
I am trying to use mMediaPlayer.getMedia().getTrackCount() and mMediaPlayer.getSpuTracksCount() which are returning zero in all cases; even the basic audio and video tracks are not counted.
Any help on this?
Note: I compiled LibVLC from [https://wiki.videolan.org/AndroidCompile/] and got the .aar archive to my project.
You might need to call media.parse() first, so you can be able to discover spu tracks and then set one.
An argument added to options will help show the subtitles:
// Create LibVLC
ArrayList<String> options = new ArrayList<String>();
options.add("-vvv"); // verbosity
options.add("--autoscale");
args.add("--sub-track=0");//this option is used to show the first subtitle track
libvlc = new LibVLC(this, options);
holder.setKeepScreenOn(true);
// Creating media player
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setAspectRatio("16:9");
mMediaPlayer.setEventListener(mPlayerListener);
// Seting up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurface);
if (mSubtitlesSurface != null)
vout.setSubtitlesView(mSubtitlesSurface);
vout.setWindowSize(1920,1080);
vout.addCallback(this);
vout.attachViews();
Media m = new Media(libvlc, Uri.parse(media));
mMediaPlayer.setMedia(m);
mMediaPlayer.play();
After a one day search i just found a proper solution for this and wanted to contribute this question with my answer.
selected answer will only show first subtitle option (if it is exist).
This one will give you full control with subtitles and audio of a media
MediaPlayer.TrackDescription[] spuTracks = mMediaPlayer.getSpuTracks();
mMediaPlayer.setSpuTrack(spuTracks[n].id);
MediaPlayer.TrackDescription[] audioTracks= mMediaPlayer.getAudioTracks();
mMediaPlayer.setAudioTrack(audioTracks[n].id);
Exoplayer library seems so complex for me. Can anyone help me how to stream radio station url using exoplayer library? I tried with MediaPlayer , it works fine but it took so much time to prepare. Here is what I tried.
exoPlayer = ExoPlayer.Factory.newInstance(RENDERER_COUNT);
Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
DataSource dataSource = new DefaultUriDataSource(getApplicationContext(), null, userAgent);
Mp3Extractor extractor = new Mp3Extractor();
ExtractorSampleSource sampleSource = new ExtractorSampleSource(
uri, dataSource, extractor, allocator, BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE);
MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
exoPlayer.prepare(audioRenderer);
exoPlayer.setPlayWhenReady(true);
I don't understand how to get userAgent and what is meaning of it?
Here is a nice description of what a user agent is:
user agent
Also here the definition of how a user agent should look like:
structure of user agent header
Here you can see how your browser's user agent looks like:
http://whatsmyuseragent.com/
To put it simply you can create your user agent like this:
"YourAppName/VersionCode"
Finally a description of how to use ExoPlayer to stream mp3:
Stream mp3 with ExoPlayer
In this example it is a local mp3 though, but the only difference should be the url of the mp3 and the missing user agent.
Hope this helps!
This is the simplest way to stream m3u8 files using ExoPlayer Lib.
check this code and don't forget to change the URL to yours and also change the content type as the blew code
hope to help
https://github.com/karim23/SimpleStreamPlayer/tree/master
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getApplicationContext();
setContentView(R.layout.activity_main);
//change the live streaming URL with yours.
contentUri = /*"Your mp3 URL.."*/;
// contentType = DemoUtil.TYPE_MP3;
final Intent intent = new Intent(context, VideoPlayerActivity.class).setData(Uri.parse(contentUri))
.putExtra(VideoPlayerActivity.CONTENT_ID_EXTRA, -1)
//Change the type according to the live streaming extension.
.putExtra(VideoPlayerActivity.CONTENT_TYPE_EXTRA, DemoUtil.TYPE_MP3);
liveStreamingTv =(TextView)findViewById(R.id.mainActivity_liveStreamingTv);
liveStreamingTv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(intent);
}
});
}
It was problem with codec, exoPlayer doesn't support aac+
I am developing a video based android application. I want to play a video (Video Format: mp4) from a URL. But it's not live stream video stored in the server. Get video URL from JSON object and playing video. The video is playing but not in a good manner.
Sometimes the audio is mismatched then take more time to play some take more time to buffer. But with the same video and same wifi speed I have on my system when playing with chrome it's playing well. I don't know what I am doing wrong? I also tried with android video view but the same problems occurred.
My code to start video player
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(uri), "video/*");
startActivity(intent);
My code to playing with video view
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.start();
What android version did you try? Because https is not supported before android 3.1.
Check supported protocols and media formats here
You can use the MediaPlayer to do this.
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Map<String, String> headers = new HashMap<String, String>();
headers.put("rtsp_transport", "tcp");
headers.put("max_analyze_duration", "500");
mMediaPlayer.setDataSource(context, Uri.parse(videoUrl), headers);
I'm using this piece of code to try and open a .mp4 video:
VideoView videoView=(VideoView)findViewById(R.id.videoView1);
MediaController mediaController=new MediaController(this);
mediaController.setAnchorView(videoView) ;
videoView.setVideoPath("R.raw.videoname");
videoView.setMediaController(mediaController) ;
videoView.start();
However, whenever I try to run the app, I get a message saying "Can't play this video". I am using a new Nexus 7 tablet if that means anything.
Also, when I try to open the same file that I have stored in with my movies, the video runs perfectly normally when I use Gallery or Video Player to open it.
Any help is much appreciated.
File file = new File(getFilePath());//file path of your video
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
String type = map.getMimeTypeFromExtension(ext);
if (type == null)
type = "*/*";
Uri uri = Uri.parse("www.google.com");
Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
Uri data = Uri.fromFile(file);
type_intent.setDataAndType(data, type);
startActivity(type_intent);
Make sure there will be no space in video name, otherwise it will not
be played by android VideoView.
If not solved then let me know.
I have video player, video is from url. It works- I can start and stop playing video. I would like to have a possibility to move progres in MediaController. I have set the MediaController, but it doesn't work. When I use a video from file i can seek/move the video progress, but with the video from url it doesn't work.
There is my code:
videoFrame = (FrameLayout) findViewById(R.id.videoField);
mediaController = new MediaController(VideoPage.this);
videoPlayer = new VideoView(context);
videoFrame.addView(videoPlayer);
videoPlayer.setVideoURI(Uri.parse(url));
mediaController.setMediaPlayer(videoPlayer);
videoPlayer.setMediaController(mediaController);
videoPlayer.requestFocus();
videoPlayer.start();
You have to check if you can seek forward:
if(videoPlayer.canSeekForward()){
...
}
and this is just possible, when you get a duration for the videostream, but some streams don't have a duration, for example if you stream tv content or a live stream.
int duration = videoPlayer.getDuration()