移动应用程序设计基础——安卓动画与视音频播放器的实现
《移动应用程序设计基础》实验6 安卓动画与视音频播放器的实现
实验名称:
实验6 安卓动画与视音频播放器的实现
所使用的工具软件及环境:
JDK1.8,Android Studio
一、实验目的:
【目的】
通过本实验,使得学生掌握导航的制作基本方法,掌握安卓动画和多媒体播放器的制作。
【实验设备】
安装Android Studio的电脑一台,同时安装模拟器或者Android手机真机一台,保证网络畅通。
二、实验内容:
【实验内容】
- 实现底部导航功能,包括Tween动画、Frame动画、音频播放、视频播放四个按键。
- 实现动画功能,其中Tween动画可在界面选择四种类型的动画效果。
- 实现音频播放。
- 实现视频播放。
【实验过程】
底部导航实现过程按如下实例:
1.主要布局文件activity_main.xml
<?xml version="0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="edu.zstu.multipage.MainActivity"><!--容器,用来操作Fragment的增加替换等--><FrameLayoutandroid:id="@+id/fragment_container"android:layout_width="match_parent"android:layout_height="match_parent"/><!--底部菜单栏--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="70dp"android:orientation="horizontal"android:background="@android:color/darker_gray"android:layout_alignParentBottom="true"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"><LinearLayoutandroid:layout_width="0dp"android:orientation="vertical"android:layout_height="match_parent"android:layout_weight="1"><ImageButtonandroid:id="@+id/home_btn"android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingTop="5dp"android:src="@drawable/home_press"android:background="@android:color/transparent" /> |
<TextView android:id="@+id/home_txt"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="主页"android:textColor="@android:color/holo_red_dark"android:gravity="center"/></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:orientation="vertical"android:layout_height="match_parent"android:layout_weight="1"><ImageButtonandroid:id="@+id/info_btn"android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingTop="5dp"android:src="@drawable/info"android:background="@android:color/transparent"/><TextViewandroid:id="@+id/info_txt"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="消息"android:textColor="@android:color/black"android:gravity="center" /></LinearLayout></LinearLayout></RelativeLayout> |
2.第一Fragment和第二个Fragment:fragment_first.xml(为例)
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:text="FirstPage"android:textSize="24sp"android:gravity="center|center"/></LinearLayout> |
3. MainActivity
3.1声明部分
ImageButton homeBtn,infoBtn;TextView homeTxt,infoTxt;Context mContext;FragmentTransaction transaction;
3.2 初始化
mContext = this;homeBtn = (ImageButton)findViewById(R.id.home_btn);infoBtn = (ImageButton)findViewById(R.id.info_btn);homeTxt = (TextView)findViewById(R.id.home_txt);infoTxt = (TextView)findViewById(R.id.info_txt);//取得Fragment管理器Fragment firstFragment = new FirstFragment();transaction =getSupportFragmentManager().beginTransaction();//默认下将firstFragment添加到容器中transaction.add(R.id.fragment_container,firstFragment);//提交事务transaction.commit();
3.3按钮点击(实现其中一个按钮,另一个按钮参照完成)
//背景替换infoBtn.setImageResource(R.drawable.info);infoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));homeBtn.setImageResource(R.drawable.home_press);homeTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.holo_red_dark));//取得Fragment管理器Fragment firstFragment = new FirstFragment();//将新建的firstFragment替换容器中的其他片段,这将重新加载布局文件。transaction =getSupportFragmentManager().beginTransaction();transaction.replace(R.id.fragment_container,firstFragment); transaction.commit();
3.4 FirstFragment .java(SecondFragment类同)
public class FirstFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_first,null);
return v;
}
}
4.运行结果
有关底部导航的多种实现方法可参看https://blog.csdn.net/jxq1994/article/details/52573506?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.control
按实验要求分别实现Tween动画、Frame动画、音频播放和视频播放四个导航键的功能。
三、实验结果测试(完整所有代码在资源下载压缩包中,文章结尾有资源下载链接)
共5个java文件和5个相对应的xml布局文件,其中还有一些资源文件。
主要的java代码:
//MainActivity.javapackage com.example.a6;import android.Manifest;
import android.app.Activity;
import android.content.Context;import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;public class MainActivity extends AppCompatActivity {//澹版槑ImageButton homeBtn,infoBtn,musicBtn,videoBtn;TextView homeTxt,infoTxt,musicTxt,videoTxt;Context mContext;FragmentTransaction transaction;private static final int REQUEST_EXTERNAL_STORAGE = 1;private static String[] PERMISSIONS_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//鍒濆鍖�init();verifyStoragePermissions(this);homeBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//鑳屾櫙鏇挎崲infoBtn.setImageResource(R.drawable.info);infoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));musicBtn.setImageResource(R.drawable.music1);musicTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));videoBtn.setImageResource(R.drawable.video1);videoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));homeBtn.setImageResource(R.drawable.home_press);homeTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.holo_red_dark));
//鍙栧緱Fragment绠$悊鍣�Fragment_First firstFragment = new Fragment_First();
//灏嗘柊寤虹殑firstFragment鏇挎崲瀹瑰櫒涓殑鍏朵粬鐗囨锛岃繖灏嗛噸鏂板姞杞藉竷灞�鏂囦欢銆�transaction =getSupportFragmentManager().beginTransaction();transaction.replace(R.id.fragment_container,firstFragment);transaction.commit();}});infoBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {//鑳屾櫙鏇挎崲infoBtn.setImageResource(R.drawable.info_press);infoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.holo_red_dark));homeBtn.setImageResource(R.drawable.home);homeTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));musicBtn.setImageResource(R.drawable.music1);musicTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));videoBtn.setImageResource(R.drawable.video1);videoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));
//鍙栧緱Fragment绠$悊鍣�Fragment_Second secondFragment = new Fragment_Second();
//灏嗘柊寤虹殑firstFragment鏇挎崲瀹瑰櫒涓殑鍏朵粬鐗囨锛岃繖灏嗛噸鏂板姞杞藉竷灞�鏂囦欢銆�transaction =getSupportFragmentManager().beginTransaction();transaction.replace(R.id.fragment_container,secondFragment);transaction.commit();}});musicBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {infoBtn.setImageResource(R.drawable.info);infoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));homeBtn.setImageResource(R.drawable.home);homeTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));musicBtn.setImageResource(R.drawable.music2);musicTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.holo_red_dark));videoBtn.setImageResource(R.drawable.video1);videoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));Fragment_Third ThirFragment=new Fragment_Third();transaction =getSupportFragmentManager().beginTransaction();transaction.replace(R.id.fragment_container,ThirFragment);transaction.commit();}});videoBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {infoBtn.setImageResource(R.drawable.info);infoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));homeBtn.setImageResource(R.drawable.home);homeTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));musicBtn.setImageResource(R.drawable.music1);musicTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.black));videoBtn.setImageResource(R.drawable.video2);videoTxt.setTextColor(ContextCompat.getColor(mContext,android.R.color.holo_blue_dark));Fragment_Fourth FourthFragment=new Fragment_Fourth();transaction =getSupportFragmentManager().beginTransaction();transaction.replace(R.id.fragment_container,FourthFragment);transaction.commit();}});}public static void verifyStoragePermissions(Activity activity) {// Check if we have write permissionint permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);if (permission != PackageManager.PERMISSION_GRANTED) {// We don't have permission so prompt the userActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);}}private void init() {mContext = this;homeBtn = (ImageButton)findViewById(R.id.home_btn);infoBtn = (ImageButton)findViewById(R.id.info_btn);homeTxt = (TextView)findViewById(R.id.home_txt);infoTxt = (TextView)findViewById(R.id.info_txt);musicBtn=(ImageButton) findViewById(R.id.musicBtn);musicTxt=(TextView)findViewById(R.id.musicTxt);videoBtn=(ImageButton)findViewById(R.id.videoBtn);videoTxt=(TextView)findViewById(R.id.videoTxt);
//鍙栧緱Fragment绠$悊鍣�Fragment_First firstFragment = new Fragment_First();transaction =getSupportFragmentManager().beginTransaction();
//榛樿涓嬪皢firstFragment娣诲姞鍒板鍣ㄤ腑transaction.add(R.id.fragment_container,firstFragment);
//鎻愪氦浜嬪姟transaction.commit();}
}
//Fragment_First.java
package com.example.a6;import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;public class Fragment_First extends Fragment {private ImageView image;Animation anim;// Context mContext;private Button rotate,translate,alpha,scale;private Context context;@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.context=getActivity();}public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {View view = inflater.inflate(R.layout.fragment_first,container,false);image=(ImageView) view.findViewById(R.id.tween);rotate=(Button) view.findViewById(R.id.rotate);translate=(Button) view.findViewById(R.id.translate);alpha=(Button) view.findViewById(R.id.alpha);scale=(Button) view.findViewById(R.id.scale);setClickListener();Animation animation = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);animation.setDuration(5000);image.setAnimation(animation);return view;}private void setClickListener() {rotate.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {anim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);anim.setDuration(5000);
//该方法用于设置一个动画效果执行完毕后,View对象保留在终止的位置/* animation.setFillAfter(true);*/image.startAnimation(anim);Toast.makeText(context, "旋转", Toast.LENGTH_SHORT).show();}});alpha.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);alphaAnimation.setDuration(3000);AnimationSet animationSet = new AnimationSet(false);animationSet.addAnimation(alphaAnimation);// 开始播放动画。image.startAnimation(animationSet);Toast.makeText(context, "透明", Toast.LENGTH_SHORT).show();}});scale.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {anim = new ScaleAnimation(0.0f, 1.2f, 0.0f, 1.2f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f);anim.setDuration(2000);//所有属性可以通过set函数设置image.startAnimation(anim);Toast.makeText(context, "缩放", Toast.LENGTH_SHORT).show();}});translate.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {anim = new TranslateAnimation(0.0f, 1200f, 0f, 0f);anim.setDuration(2000);image.startAnimation(anim);Toast.makeText(context, "移动", Toast.LENGTH_SHORT).show();}});}
}
//Fragment_Second.javapackage com.example.a6;import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;public class Fragment_Second extends Fragment {private ImageView ivImage;private Button start,stop;private AnimationDrawable anim;@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);}public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {View v = inflater.inflate(R.layout.fragment_second,null);ivImage = (ImageView) v.findViewById(R.id.frame_image);start=(Button) v.findViewById(R.id.startframe);stop=(Button) v.findViewById(R.id.stopframe);ivImage.setBackgroundResource(R.drawable.frame);anim = (AnimationDrawable) ivImage.getBackground();ivImage.post( new Runnable() {@Overridepublic void run() {anim.start();}});setClickListener();return v;}private void setClickListener() {stop.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {anim.stop();}});start.setOnClickListener( new View.OnClickListener() {@Overridepublic void onClick(View v) {anim.start();}});}
}
//Fragment_Third.javapackage com.example.a6;import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;import java.io.File;
import java.io.IOException;public class Fragment_Third extends Fragment {private Button play,pause,stop,replay;private ImageView music;private MediaPlayer mediaPlayer;private Context context;Animation anim;@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);context=getActivity();}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// Inflate the layout for this fragmentView view = inflater.inflate(R.layout.fragment__third,container,false);play=(Button) view.findViewById(R.id.start);pause=(Button) view.findViewById(R.id.pause);replay=(Button) view.findViewById(R.id.replay);stop=(Button) view.findViewById(R.id.stop);music=(ImageView) view.findViewById(R.id.music3);play.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {anim = new RotateAnimation(0, 3600, Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);anim.setDuration(50000);anim.setFillAfter(true);music.startAnimation(anim);mediaPlayer = new MediaPlayer();try {mediaPlayer.setDataSource("/sdcard/Music/love.mp3");mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);mediaPlayer.prepareAsync();mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {@Overridepublic void onPrepared(MediaPlayer mp) {mediaPlayer.start();Toast.makeText(context, "开始播放", Toast.LENGTH_SHORT).show();play.setEnabled(false);}});mediaPlayer.setLooping(true);mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {@Overridepublic void onCompletion(MediaPlayer mp) {play.setEnabled(true);}});mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {@Overridepublic boolean onError(MediaPlayer mp, int what, int extra) {if(mediaPlayer!=null&&mediaPlayer.isPlaying()){mediaPlayer.seekTo(0);Toast.makeText(context, "重新播放", Toast.LENGTH_SHORT).show();pause.setText("暂停");//return;}return false;}});} catch (IOException e) {e.printStackTrace();Toast.makeText(context, "播放失败", Toast.LENGTH_SHORT).show();}}});replay.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(mediaPlayer!=null&&mediaPlayer.isPlaying()){mediaPlayer.seekTo(0);Toast.makeText(context, "重新播放", Toast.LENGTH_SHORT).show();pause.setText("暂停");//return;}}});pause.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(pause.getText().toString().trim().equals("继续")){pause.setText("暂停");mediaPlayer.start();Toast.makeText(context, "继续播放", Toast.LENGTH_SHORT).show();// return;}else if(mediaPlayer!=null&&mediaPlayer.isPlaying()){mediaPlayer.pause();pause.setText("继续");Toast.makeText(context, "暂停播放", Toast.LENGTH_SHORT).show();}}});stop.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(mediaPlayer!=null&&mediaPlayer.isPlaying()){mediaPlayer.stop();mediaPlayer.release();mediaPlayer=null;play.setEnabled(true);Toast.makeText(context, "停止播放", Toast.LENGTH_SHORT).show();}}});return view;}private void setOnclick() {}public void onDestroy() {if(mediaPlayer!=null&&mediaPlayer.isPlaying()){mediaPlayer.stop();mediaPlayer.release();mediaPlayer=null;}super.onDestroy();}
}
//Fragment_Fourth.javapackage com.example.a6;import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;import java.io.IOException;public class Fragment_Fourth extends Fragment {private MediaPlayer mediaPlayer;private SurfaceView sv_main_surface;private TextView tv_start;private TextView tv_end;private SeekBar seekbar;private Context context;private ImageButton play;@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);context=getActivity();}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// Inflate the layout for this fragmentView view = inflater.inflate(R.layout.fragment__fourth,container,false);sv_main_surface = (SurfaceView) view.findViewById(R.id.sv_main_surface);tv_start = (TextView)view.findViewById(R.id.tv_start);tv_end = (TextView)view. findViewById(R.id.tv_end);seekbar = (SeekBar) view.findViewById(R.id.seekbar);play=(ImageButton)view.findViewById(R.id.bt_media);//设置监听seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {@Overridepublic void onProgressChanged(SeekBar seekBar, int i, boolean b) {//获取音乐总时间int duration2=mediaPlayer.getDuration()/1000;//获取音乐当前播放的位置int position=mediaPlayer.getCurrentPosition();//开始时间tv_start.setText(calculateTime(position/1000));//结束时间tv_end.setText(calculateTime(duration2));}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {int progress=seekBar.getProgress();//在当前位置播放mediaPlayer.seekTo(progress);}});play.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//判断音频文件是否为空if(mediaPlayer==null){//为空则创建音乐文件并播放改变按钮样式//播放内存卡中文件mediaPlayer=new MediaPlayer();try {mediaPlayer.setDataSource("/sdcard/Movies/猫和老鼠.mp4");//准备mediaPlayer.prepare();} catch (IOException e) {e.printStackTrace();}//将媒体播放器捕捉的画面展示到SurfaceViewmediaPlayer.setDisplay(sv_main_surface.getHolder());//开始播放mediaPlayer.start();//设置buttonplay.setImageResource(android.R.drawable.ic_media_pause);//获取音乐总时间int duration=mediaPlayer.getDuration();//将音乐总时间设置为SeekBar的最大值seekbar.setMax(duration);//线程修改时间值new MyThread().start();//音乐文件正在播放,则暂停并改变按钮样式}else if(mediaPlayer.isPlaying()){mediaPlayer.pause();play.setImageResource(android.R.drawable.ic_media_play);}else{//启动播放mediaPlayer.start();play.setImageResource(android.R.drawable.ic_media_pause);}}});return view;}public void isPlayOrPause(View view){}class MyThread extends Thread{@Overridepublic void run() {super.run();while(seekbar.getProgress()<=seekbar.getMax()){//获取音乐当前播放的位置int position=mediaPlayer.getCurrentPosition();//放入SeekBar中seekbar.setProgress(position);}}}//计算播放时间public String calculateTime(int time){int minute;int second;if(time>=60){minute=time/60;second=time%60;return minute+":"+second;}else if(time<60){second=time;return "0:"+second;}return null;}
}
实验结果截图:
心得与体会:
本次实验,学习了Fragment的用法以及学会Tween四种alpha,translate,rotate,scale动画、Frame逐帧动画和音频播放,视频播放等。通过此次实验,学习到的知识颇多,对android的开发有了进一步的学习。
下载资源包链接:
https://download.csdn.net/download/weixin_48388330/76309689
资源中的图片以及内容只适用与学习
移动应用程序设计基础——安卓动画与视音频播放器的实现相关推荐
- 自己做的视音频播放器,绿色版,欢迎使用
由于做视音频开发,自己机器里有很多播放器和视音频工具,很多播放器都有广告.恶意插件什么,很烦人,所以自己做了一款自用的播放器,绿色版,无需安装,基本上大多数格式都支持,用起来还行,打算下一步做一些常用 ...
- 最简单的视音频播放示例2:GDI播放YUV, RGB
===================================================== 最简单的视音频播放示例系列文章列表: 最简单的视音频播放示例1:总述 最简单的视音频播放示例 ...
- 最简单的视音频播放示例7:SDL2播放RGB/YUV
最简单的视音频播放示例系列文章列表: 最简单的视音频播放示例1:总述 最简单的视音频播放示例2:GDI播放YUV, RGB 最简单的视音频播放示例3:Direct3D播放YUV,RGB(通过Surfa ...
- 最简单的视音频播放示例9:SDL2播放PCM
本文记录SDL播放音频的技术.在这里使用的版本是SDL2.实际上SDL本身并不提供视音频播放的功能,它只是封装了视音频播放的底层API.在Windows平台下,SDL封装了Direct3D这类的API ...
- 最简单的视音频播放演示样例5:OpenGL播放RGB/YUV
===================================================== 最简单的视音频播放演示样例系列文章列表: 最简单的视音频播放演示样例1:总述 最简单的视音频 ...
- 最简单的视音频播放示例8:DirectSound播放PCM
===================================================== 最简单的视音频播放示例系列文章列表: 最简单的视音频播放示例1:总述 最简单的视音频播放示例 ...
- 最简单的视音频播放示例6:OpenGL播放YUV420P(通过Texture,使用Shader)
===================================================== 最简单的视音频播放示例系列文章列表: 最简单的视音频播放示例1:总述 最简单的视音频播放示例 ...
- 最简单的视音频播放示例5:OpenGL播放RGB/YUV
===================================================== 最简单的视音频播放示例系列文章列表: 最简单的视音频播放示例1:总述 最简单的视音频播放示例 ...
- 最简单的视音频播放示例1:总述
===================================================== 最简单的视音频播放示例系列文章列表: 最简单的视音频播放示例1:总述 最简单的视音频播放示例 ...
最新文章
- 一项无聊的研究与论文,导致整个大学被Linux封杀!
- 能做存储的超级计算机——任宇翔和以色列团队的创业故事
- python3获取两个日期之间所有日期,以及比较大小
- clickhouse的ReplacingMergeTree引擎实战
- 04 16 团队竞技(第二场) 赛后总结
- 错误:在非结构或联合中请求成员‘next’
- linux下Makefile学习--注释很好
- 你觉得人生最好的年龄段是哪段时间?
- 计算机网络-自顶向下方法(7th) 第一章 Review Questions 中英对照
- 如何在不确定经济形势下把握好企业脉搏
- button是块级元素吗_前端面试必知必会的十点,你都知道吗?
- BZOJ1076[SCOI2008] 奖励关
- Python 操作pdf文件-合并操作 (三)
- Vista Ultimate X64 绝对正宗的激活工具
- 不支持虚拟化的cpu如何开VM虚拟机(不支持,即“主机不支持Intel VT-x,不是支持Intel VT-x,但Intel VT-x禁处于禁用状态!!!!!!)
- 外媒的指责恰恰反映华为的通信设备足够安全、技术领先
- C++Qt入门(1)---Qt简介,第一个Qt程序,Qt按钮
- linux调节伽马值软件,四个 Linux 下的“护眼”软件
- citra 图形设置_bios怎么设置硬盘启动顺序 bios设置硬盘启动方法
- CentOS 7 几个版本