Android Streaming Video - Need Aspect Ratio

I am using the Android MediaPlayer demo for Video. I have streaming video 640x480. I simply want the video to be as large as it can be (in whatever device orientation) while keeping aspect ratio. I can't get it to do this. It simply stretches across the entire screen. My SurfaceView in the layout doesn't maintain aspect ratio in either "fill_parent" or "wrap_content". When I check (and change the surface size in code, it seems to ignore any changes. And what is weird is I am told in this code that my video size is : 176 x 144.

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { Log.v(TAG, "onVideoSizeChanged called"); Log.v(TAG, "Surface Width: " + width + " Surface Height: " + height); if (width == 0 || height == 0) { Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")"); return; } mIsVideoSizeKnown = true; mVideoWidth = width; mVideoHeight = height; mVideoWidth = mp.getVideoWidth(); mVideoHeight = mp.getVideoHeight(); Log.v(TAG, "Surface Width: " + mVideoWidth + " Surface Height: " + mVideoHeight); if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) { startVideoPlayback(); } }

This is where I try and change the size:

private void startVideoPlayback() { Log.v(TAG, "startVideoPlayback"); holder.setFixedSize(mVideoWidth, mVideoHeight); mMediaPlayer.start(); }

Thoughts?

-------------Problems Reply------------

try to use setLayoutParams() in OnPrepared()

public void onPrepared(MediaPlayer mp) {
...
mSurfaceView.setLayoutParams(new LinearLayout.LayoutParams(vWidth, vHeight));
...
};

Category:android Views:2 Time:2011-06-07

Related post

  • HTML5 Video: Retain aspect ratio when resizing 2010-10-21

    I have a video element set to 100% width in a container div. That div has a max-width of 800px and min-width of 400px. When resizing the browser I need the video element to resize while retaining its original aspect ratio. Currently it resizes in wid

  • android Gallery with arbitrary aspect ratios 2011-04-18

    i wish to have an android gallery that will host images of varying aspect ratios. what i'd like is something like CENTER_CROP for the images in the gallery. however, when i set the image scale type to this, the images overrun the gallery image border

  • Android: How to maintain aspect-ratio in animation 2011-05-16

    The animation I am running inside an imageview refuses to maintain the aspect-ratio of the image frames. The following answers in SO are quite informative, but don't seem to work for me: How to scale an Image in ImageView to keep the aspect ratio Her

  • Android Streaming Video using MediaPlayer 2011-09-29

    I'm back with another problem! I'm trying to create an app that would list a selected Livestreams, from Own3d.TV, Justin.Tv etc... If my research isn't totally failed, I can use the MediaPlayer object to Stream video, the only question is how do I us

  • Android Stream Video From PC 2012-01-17

    im interested in writing an Android program that plays video stream from a local PC on my network. Ive had a look at the API's and understand the principle behind the code. What i was interested in is the media server on the PC side, does anybody hav

  • Android layouts based on aspect ratio? 2012-02-07

    This is a bit hard to explain, so I'll try with an example. Let's say I've got a 3:2 image, that it'd like in one of my applications. I'd like the width of the ImageView to match its parent (match_parent), and I'd like the height to scale according t

  • imported tif file is streched when video plays, aspect ratio is not maintained 2012-05-23

    Question Summary Other Windows Live Movie Maker issues Which version of Windows Live Movie Maker are you using ? Version 2011 (15.4.3502.922) Choose your Operating System version : Windows 7 Additional Details i tried putting a picture of a drawing i

  • Android Streaming Video: Does anyone know why the direct path of youtube videos that keepvid.com finds only works locally? 2012-03-30

    I am trying to stream a youtube video within an android application I am developing. I understand I could just leave this to youtube's app or download the video and throw it in the res folder to play it locally, but after trying both of these methods

  • Controlling Flowplayer Video Aspect Ratio 2013-06-27

    Hello I am developing an online video streaming website. I am using flowplayer(HTML5) to run the videos. I have a question; is it possible to control aspect ratio of the player? I ask this because for some mp4 videos, an aspect ratio of 0.5625 seems

  • Confused about pixel aspect ratio and video size 2013-11-09

    Hello, I have edited a whole dvd full of video and exported it as MPEG-2 NTSC DV Wide - it says 720 x 480, 29.97 fps. I have brought these into Encore and am trying to make a menu but can't seem to get the menu size right. Since I chose the wide form

  • Need to display streaming video occupying the fullscreen 2010-09-09

    I am using VideoView component for streaming video in Android , but the streaming video is occupying only a part of the screen of the mobile device both in portrait/landscape mode. Kindly provide the code to so that the streaming video is displayed c

  • Finding a video's aspect in Objective C 2010-12-15

    I'm looking for a way to find either a video's aspect ratio in Objective-C (C would be fine as well though). I'm using a QTMovie if that helps. --------------Solutions------------- Just from the documentation, the QTMovieNaturalSizeAttribute of the m

  • Aspect ratio in media player (vista and win 7) 2015-01-31

    Hello, On xp when i entered the setting in media player tool>options>devices>display>properties. I could change the video played aspect ratio. It worked fine. But when i enter these settings in win 7 32 or vista 64 these settings doesnt w

  • How to maintain aspect-ratio when playing RTSP streaming video in Android? 2011-03-28

    I have a streaming RTSP video link which I am playing with the help of VideoView. In the portrait mode the Video resolution and aspect ratio is perfect. But when I try switching to the landscape mode the video stretches and looks elongated. This dist

  • Window Phone 8 displays video in the wrong aspect ratio. Android and iOS do not. 2013-10-25

    Both WP 8 & 7.5 play videos in the wrong aspect ratio. The same videos play in the correct aspect ratio on Android 4.0+ and iOS 5.0+. The video files were created from ripped DVD movies and converted to MP4/h264/AAC video using Handbrake program,

  • Android: MediaPlayer video aspect ratio issue 2011-11-23

    I am having an issue that I am unable to resolve. I am using MediaPlayer class to play video; however, I am always loosing the original aspect ratio. The media player code and the xml code is mentioned here. I have tried so many things but still not

  • creating video for android streaming 2012-03-26

    This is answer for my search which i did for creating videos to stream on android. Though android supports mp4 for streaming but not easily. The simple steps which i deduced from my experience are:- 1) using super encoder first of all encode the vide

  • Get aspect ratio of video from FFmpeg 2010-12-12

    I am using FFmpeg to convert a video from one format to another. I need to extract the aspect ratio of the video first. How can I find that information? --------------Solutions------------- Just run ffmpeg -i <yourfilename> and details about th

  • Android and video streaming 2012-02-16

    I have this code : @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String url = "http://people.sc.fsu.edu/~jburkardt/data/mp4/cavity_flow_movie.mp4"; videoPlayer(url); } p

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.116 (s). 11 q(s)