Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8425169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:11:52+00:00 2026-06-10T04:11:52+00:00

I am trying to play video from streaming url. the code is as following

  • 0

I am trying to play video from streaming url. the code is as following

public class VideoPlayer extends Activity  
{
    private VideoView mVideoView;            
    String videoURL="";
    static Utility utility;
    static Context context;
    MediaController mediaController;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {         
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video_player);          
        setupViews();
    }

    private void setupViews() 
    {
        context=VideoPlayer.this;
        utility=new Utility(VideoPlayer.this);
        isActivityisRunning=true;
        showProgressDialog("Loading video..");
        videoURL=getIntent().getExtras().getString("url");            
        mVideoView=(VideoView)findViewById(R.id.video_view);
        mediaController=new MediaController(context);            
        mVideoView.setMediaController(mediaController);

        mVideoView.setOnPreparedListener(new OnPreparedListener() 
        {
            @Override
            public void onPrepared(MediaPlayer mp) 
            {
                hideProgressDialog();

                if(bIsOnPausedCalled)
                    mVideoView.seekTo(LastDuration);
                    mVideoView.start();                     
                    mVideoView.requestFocus();  
                    bIsOnPausedCalled=false;
                    LastDuration=0;
                }
            });

           mVideoView.setOnCompletionListener(new OnCompletionListener() 
            {

                @Override
                public void onCompletion(MediaPlayer mp) 
                {
                    finish();
                }
            }); 


           mVideoView.setOnErrorListener(new OnErrorListener() 
           {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) 
            {
                utility.hideProgressDialog();
                return false;
            }
        });

           playVideoFile();      
        } 

    public static void showDialog(String Message)
    {       
                alertDialog = new AlertDialog.Builder(context).create();  
                alertDialog.setTitle(Constant.DialogTitle);  
                alertDialog.setMessage(Message);  
                alertDialog.setCancelable(false);
                alertDialog.setButton("Ok", new DialogInterface.OnClickListener() 
                {  
                          public void onClick(DialogInterface dialog, int which) 
                          {             
                             dialog.dismiss();                          
                          } 
                }); 
                if(isActivityisRunning)
                    alertDialog.show();
                else
                    utility.showToast(Message);
    }

    static ProgressDialog progressDialog;
    static AlertDialog alertDialog;

    public  void showProgressDialog(String Message)
    {   
            hideProgressDialog();
            progressDialog=new ProgressDialog(context);
            progressDialog.setTitle(Constant.DialogTitle);
            progressDialog.setMessage(Message);                         
            if(isActivityisRunning)
                progressDialog.show();
            else
                utility.showToast(Message);
    }

    public static boolean isActivityisRunning;
    public static boolean showProgressDialog;


    public static boolean bIsOnPausedCalled=false;
    public static int LastDuration=0;

        @Override
        protected void onPause() 
        {   

            hideProgressDialog();
            bIsOnPausedCalled=true;
            isActivityisRunning=false;
            if (mVideoView != null)
            {       
                if(LastDuration==0)
                {
                    LastDuration=mVideoView.getCurrentPosition();
                    mVideoView.suspend();
                    mVideoView.setVisibility(View.GONE);    
                }               
            }
            super.onPause();
        }

        @Override
        protected void onResume() 
        {

            isActivityisRunning=true;
                if(bIsOnPausedCalled)
                {                       
                    setupViews();               
                }
                super.onResume();       
        }

        @Override
        protected void onDestroy() 
        {
            super.onDestroy();
            try 
            {               
                if (mVideoView != null) 
                {   
                    mVideoView.stopPlayback();
                    mVideoView=null;                
                    hideProgressDialog();
                    isActivityisRunning=false;
                     bIsOnPausedCalled=false;
                     LastDuration=0;
                }

            } catch (Exception e) 
            {}              
        }


    public static void hideProgressDialog()
    {
        if(progressDialog!=null)
        {
            if(progressDialog.isShowing())
            {
                progressDialog.dismiss();
            }           
        }
    }


    private void playVideoFile() 
        {

                try 
                {                   
                    mVideoView.setVideoURI(Uri.parse(videoURL));
                }
                catch (Exception e) 
                {
                    utility.hideProgressDialog();
                    if (mVideoView != null) 
                    {                   
                        mVideoView.stopPlayback();
                    }
                }
            }   

This works fine on android device having version below 4.0 (with pause and resume with sleep mode button).
but when i am trying to play video on android phone having version4.0 or later
video will play fine but when phone goes to sleep mode and resume back from sleep mode
the video view size became half of screen. as followingenter image description here

please help?

Thanks in Advance…..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:11:54+00:00Added an answer on June 10, 2026 at 4:11 am

    you are doing is all correct but you have applied setContentView(R.layout.video_player);
    only ones ,even though video is resumed.
    so code should be

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {         
        super.onCreate(savedInstanceState);                
        setupViews();
    }
    
    private void setupViews() 
    {
        setContentView(R.layout.video_player);  
        context=VideoPlayer.this;
        -----
        ------
    }
    

    Instead of

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {         
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.video_player);       
        setupViews();
    }
    
    private void setupViews() 
    {
        context=VideoPlayer.this;
        -----
        ------
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play a video from URL on videoView. Video extension is
I'm trying to play video from youtube using this code but I get this
So, I'm trying to get a video to play from an HTTP url. To
So I'm trying to play a video and the following code has worked for
i am trying to play a video from a Url with help of MPMovieplayer
I am trying to play a video from video path that I have in
I'm working with PyQt and trying to get video from a webcam to play
I'm trying to play a video in a VideoView and I'm failing miserably. I'm
I am trying to play video files from iPhone media player in my iphone
I am trying to play video files from http urls in my app. Why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.