Monday 15 June 2015

android - Using surfaceview and fragments to display video. Video doesn't show but I have sound, -


I have seen many posts with the same issue, but I still can not fix my problem I have an MP4 video I am using surface visual, fragments and mediation to play. I get audio, but there is no problem outside the video app but no video. I have tried different formats, but there is no luck. I am not using an emulator. I am using Samsung Galaxy Tab 2 to test. What am I missing in showing the video?

Here is my XML file:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: orientation = "vertical" & gt; & Lt; SurfaceView android: id = "@ + id / video_surfaceView" Android: layout_weight = "1" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" & gt; & Lt; / SurfaceView & gt; & Lt; Android: id = "@ + id / playvideoplayer" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" android: text = "- PLAY" / & gt; & Lt; Button android: id = "@ + id / pausevideoplayer" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" android: text = "- PAUSE" / & gt; Android: Android: Android: Android: Android: Android: Layout_Hild = "Rap_Cent" Android: Text = "- Stop" /> & Lt; / LinearLayout & gt;   

This is my code:

  The public class chapter extends the Video Fragment Fragment {Personal Static Last String TAG = "Chapter Videfragment"; Private stable final Boolean VERBOSE = true; Private SurfaceView mSurfaceView; Private Surface Holder Marsfaceholder; Private Media Player MP = Faucet; Private button embedlive, MPOS video, mStopVideo; Private boolean mPausing = false; @ Override public view curve (layoutInflator Inflator, View Group Parent, Bundle Saved InstantState) {if (Verbose) Log V (tag, "+++ creative +++"); V = see inflater.inflate (R.layout.fragment_video, parent, wrong); MSurfaceView = (SurfaceView) v.findViewById (R.id.video_surfaceView); MPlayVideo = (button) v.findViewById (rid.pavideoplayer); MPauseVideo = (button) v.findViewById (R.id.pausevideoplayer); MStopVideo = (button) v.findViewById (R.D.StopwidEoplayer); MP = media player (getActivity), ROIIIMprovisation); MPlayVideoksetOnClickListener (New View.OnClickListener () {see public void onClick () {mp.setAudioStreamType (AudioManager.STREAM_MUSIC); // Video integer dimensions videoWidth = mp.getVideoWidth get () Integer videoHeight = mp. getVideoHeight () ; // screen int width must screenWidth = getActivity () getWindowManager () getDefaultDisplay () getWidth (a); ... // SurfaceView layout parameters get android.view.ViewGroup.LayoutParams LP = mSurfaceView.getLayoutParams () ; // Set the width of the surface view in the width of the screen lp.width = screenWidth; // Surf to match the aspect ratio of the video Determine the height of aceView ensure // add them as Flots otherwise likely count will be 0 lp.height = (int) (((float) videoHeight / (float) videoWidth) * (float) screenWidth); // Committed layout parameters mSurfaceView.setLayoutParams (LP); //mp.setDisplay (MSurfaceView.getHolder ()); mp.start ();}});   

Here is the code for the surface:

  mSurfaceHolder = mSurfaceView.getHolder (); MSurfaceHolderkaddCallback (New SurfaceHolder.Callback () {@Override public void surfaceDestroyed (SurfaceHolder arg0) {// TODO Auto-generated method stub} @Override public void surfaceCreated (SurfaceHolder arg0) {if (words) Log.v (TAG, "+++ surfaceCreated +++"); // TODO auto-created method stub} @Override Public Zero SurfaceChanged (SurfaceHolder arg0, integer ARG1, integer aRG2, integer arg3) {// TODO auto-created method stub}}) ; Try using Videoview - It is possible that the device on which you are using to display the video does not support the format in the Media Player object, I solved the problem with videoview   

No comments:

Post a Comment