3

如何在 android 模拟器中在后台播放视频时在 android 中加载活动布局???视频演示,您可以在此处看到 示例视频

到目前为止,我只为布局设置了动画,但我无法像视频中的那样做,当我尝试在模拟器中只播放视频时,它会给出错误提示“无法播放视频”实际上我没有安卓设备所以我必须在模拟器中测试我的应用程序。非常感谢任何帮助。

这是动画代码:

package com.example.test;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.VideoView;

public class CorporateProfileActivity extends Activity implements OnPreparedListener, OnCompletionListener{

    public ImageView bbhome, bbmap, bbprojects, bbcontact, bbprofile;
    private VideoView video;
    private ImageView ivcp1, ivcp2, ivcp3, ivcp4, ivcp5, ivcp6;
    Animation forcp1, forcp2, forcp3, forcp4, forcp5, forcp6, animation;
    View view, view1, view2;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile);

        //below bar variables
        bbhome = (ImageView) findViewById(R.id.bbhome);
        bbmap = (ImageView) findViewById(R.id.bbmap);
        bbprojects = (ImageView) findViewById(R.id.bbprojects);
        bbcontact = (ImageView) findViewById(R.id.bbcontact);
        bbprofile = (ImageView) findViewById(R.id.bbprofile);

        animation = AnimationUtils.loadAnimation(this, R.anim.intro_scale);
        //animation.setFillAfter(true);

        video=(VideoView) findViewById(R.id.VideoView1);

        //images in order from left to right
        ivcp1 = (ImageView)findViewById(R.id.cp1);
        ivcp2 = (ImageView)findViewById(R.id.cp2);
        ivcp3 = (ImageView)findViewById(R.id.cp3);
        ivcp4 = (ImageView)findViewById(R.id.cp4);
        ivcp5 = (ImageView)findViewById(R.id.cp5);
        ivcp6 = (ImageView)findViewById(R.id.cp6);

        forcp1 = new TranslateAnimation(-1500, 0, 0, 0);
        forcp1.setDuration(700);

        forcp2 = new TranslateAnimation(-1200, 0, 0, 0);
        forcp2.setDuration(800);

        forcp2.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // TODO Auto-generated method stub
                ivcp1.setVisibility(1);
                ivcp1.startAnimation(forcp1);
            }
        });

        forcp3 = new TranslateAnimation(-1000, 0, 0, 0);
        forcp3.setDuration(800);

        forcp3.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // TODO Auto-generated method stub
                ivcp2.setVisibility(1);
                ivcp2.startAnimation(forcp2);
            }
        });

        forcp4 = new TranslateAnimation(-500, 0, 0, 0);
        forcp4.setDuration(800);

        forcp4.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // TODO Auto-generated method stub
                ivcp3.setVisibility(1);
                ivcp3.startAnimation(forcp3);
            }
        });

        forcp5 = new TranslateAnimation(-500, 0, 0, 0);
        forcp5.setDuration(800);

        forcp5.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // TODO Auto-generated method stub
                ivcp4.setVisibility(1);
                ivcp4.startAnimation(forcp4);
            }
        });

        forcp6 = new TranslateAnimation(-500, 0, 0, 0);
        forcp6.setDuration(800);
        ivcp6.setVisibility(1);
        ivcp6.startAnimation(forcp6);

        forcp6.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // TODO Auto-generated method stub
                ivcp5.setVisibility(1);
                ivcp5.startAnimation(forcp5);
            }
        });




        //image click events
        ivcp1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ivcp1.startAnimation(animation);
                openIntro(view1);
            }
        });

        ivcp2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ivcp2.startAnimation(animation);
                openWhoWeAre(view);
            }
        });

        ivcp3.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ivcp3.startAnimation(animation);
                openThwWayWeWork(v);
            }
        });

        ivcp4.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ivcp4.startAnimation(animation);
                openMisionVision(v);
            }
        });

        ivcp5.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ivcp5.startAnimation(animation);
                openOurPrinciples(v);
            }
        });

        ivcp6.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ivcp6.startAnimation(animation);
                openPromoter(v);
            }
        });


        //onclick event for below bar menus
        bbhome.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                bbhome.setImageResource(R.drawable.home_active);
                openMainActivity(v);
            }
        });

        bbmap.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });

        bbprojects.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });

        bbcontact.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });

        bbprofile.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });
    }

    //open methods to open activity
    public void openIntro(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, IntroductionActivity.class);
        startActivity(intent);
    }

    public void openWhoWeAre(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, WhoWeAreActivity.class);
        startActivity(intent);
    }

    public void openThwWayWeWork(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, WhoWeAreActivity.class);
        startActivity(intent);
    }

    public void openMisionVision(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, WhoWeAreActivity.class);
        startActivity(intent);
    }

    public void openOurPrinciples(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, WhoWeAreActivity.class);
        startActivity(intent);
    }

    public void openPromoter(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, WhoWeAreActivity.class);
        startActivity(intent);
    }


    /*
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
     */

    @Override
    public void onCompletion(MediaPlayer mp) {
        // TODO Auto-generated method stub
        System.out.println("video is complete...");
        //imageView.setVisibility(View.VISIBLE);
        //imageView.setScaleType(ImageView.ScaleType.FIT_XY);   
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        // TODO Auto-generated method stub

    }

    public void openMainActivity(View view) {
        // Do something in response to button
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
    }

}
4

0 回答 0