Android Studio音频视频播放器课程设计

打印 上一主题 下一主题

主题 582|帖子 582|积分 1746

这个项目得当刚刚学习Android studio的初学者,实现音视频的基本播放功能,各项功能的页面都做的比力简单,特别适用于初学者,其特点在于本项目抛开了各种花里胡哨的制作,以最靠近初学者的样式画面呈现,完全不用担心被质疑套用别人的项目,要是着实追求完美的话,本文末端也附上了颠末美化后的雷同项目链接。
基于Android Studio的音视频播放系统设计与实现
一、标题形貌
音视频播放系统包罗:使用sqlite创建数据库用于存储用户信息、启动效果、用户注册、用户登录、表现用户信息、音乐播放、视频播放等功能。
二、功能形貌
设计一个音视频播放器app,使之能够实现以下功能:

  • 创建一个数据库用于存储用户信息。
  • 启动效果:该App设计了启动页面,启动后倒计时3s后可进入app。
  • 用户登录注册:该App提供用户登录和注册功能,用户可以创建新账户或使用现有账户登录。当用户注册完成后跳转回到登录页面举行用户登录。用户需要提供有效的用户名和暗码举行身份验证。
  • 表现用户信息:用户登录后可点击信息按钮查看用户信息,包罗汗青登任命户的用户信息。
  • 音乐播放功能:用户登录后,可以通过该App浏览和播放音乐文件。App提供音乐列表,用户可以浏览并选择要播放的音乐。点击音乐后,将跳转到音乐播放页面,可举行音乐的播放、停息、上一曲和下一曲以及拖动进度条来控制音乐播放。
  •  视频播放功能:该App还提供视频播放功能。用户可以通过App浏览并选择要播放的视频文件。点击视频后,跳转到音乐播放页面,可以控制视频播放和停息。
三、功能实现
项目目次:

 1.创建数据库,创建一个用户表,表布局如下:

2.实现app启动页面,页面效果如下:

 3.实现用户登录功能,用户需要提供有效的用户名和暗码,否侧提示用户名无效或暗码无效:

4.实现用户注册功能,点击注册按钮跳转至用户注册页面,用户注册成功跳转回用户登录页面举行用户登录:


5.表现汗青登任命户信息功能,登录成功后,点击信息后,跳转至用户信息表现界面,用户可查看汗青登任命户信息。

6.实现音乐播放功能,登录成功后,默认表现音乐列表,点击音乐后,跳转至音乐播放界面,用户可通过点击播放按钮举行音乐的播放、停息、上一曲和下一曲操作,同时用户也可以通过拖动进度条控制音乐的播放进度:

7.实现视频播放功能,在默认页面点击视频按钮后,跳转至视频列表,点击视频可进入视频播放页面,用户可通过点击播放、停息、继承播放按钮对视频举行播放控制。

四、源代码
1.用户类界说User.java

  1. package and.yjg.music_app.Login;
  2. public class User {
  3.     public User() {
  4.     }
  5.     public User(String account, String password, String phone, String address) {
  6.         this.account = account;
  7.         this.password = password;
  8.         this.phone = phone;
  9.         this.address = address;
  10.     }
  11.     public String account;
  12.     public String password;
  13.     public String phone;
  14.     public String address;
  15.     public String getAccount() {
  16.         return account;
  17.     }
  18.     public void setAccount(String account) {
  19.         this.account = account;
  20.     }
  21.     public String getPassword() {
  22.         return password;
  23.     }
  24.     public void setPassword(String password) {
  25.         this.password = password;
  26.     }
  27.     public void setPhone(String phone) {
  28.         this.phone = phone;
  29.     }
  30.         public void setAddress(String address){
  31.             this.address = address;
  32.         }
  33.         public String toString () {
  34.             return "用户名:" + account + "\n" +
  35.                     "密码:" + password + "\n " +
  36.                     "电话:" + phone + "\n " +
  37.                     "地址:" + address + "\n";
  38.         }
  39.     }
复制代码
2.UserDao.java
  1. package and.yjg.music_app.Login;
  2. import android.content.ContentValues;
  3. import android.content.Context;
  4. import android.database.Cursor;
  5. import android.database.sqlite.SQLiteDatabase;
  6. import android.database.sqlite.SQLiteException;
  7. import android.util.Log;
  8. import and.yjg.music_app.DataBaseHelper;
  9. public class UserDao {
  10.     private Context context;       
  11.     private DataBaseHelper dbHelper;
  12.     private SQLiteDatabase db;   
  13.     public UserDao(Context context) {
  14.         this.context = context;
  15.     }
  16.     public void open() throws SQLiteException {
  17.         dbHelper = new DataBaseHelper(context);
  18.         try {
  19.             db = dbHelper.getWritableDatabase();
  20.         } catch (SQLiteException exception) {
  21.             db = dbHelper.getReadableDatabase();
  22.         }
  23.     }
  24.     public void close() {
  25.         if (db != null) {
  26.             db.close();
  27.             db = null;
  28.         }
  29.     }
  30.     public void addUser(User user) {
  31.         ContentValues values = new ContentValues();
  32.         values.put("account", user.account);
  33.         values.put("password", user.password);
  34.         values.put("phone", user.phone);
  35.         values.put("address", user.address);
  36.         db.insert("user", null, values);
  37.     }
  38.     public void deleteUser(User user) {
  39.         db.delete("user", "account = ?", new String[]{user.account});
  40.     }
  41.     public void update(User user) {
  42.         ContentValues values = new ContentValues();
  43.         values.put("password", user.password);
  44.         db.update("user", values, "account = ?", new String[]{user.account});
  45.     }
  46.     public boolean find(User user) {
  47.         Cursor cursor = db.query("user", null, "account = ?", new String[]{user.account}, null, null, null);
  48.         if (cursor == null || cursor.getCount() < 1) {
  49.             return false;
  50.         }
  51.         if (cursor.moveToFirst()) {
  52.             do {
  53.                 String acc = cursor.getString(cursor.getColumnIndex("account"));
  54.                 String pass = cursor.getString(cursor.getColumnIndex("password"));
  55.                 String pho = cursor.getString(cursor.getColumnIndex("phone"));
  56.                 String addr = cursor.getString(cursor.getColumnIndex("address"));
  57.                 Log.d("UserDao", "user account is" + acc);
  58.                 Log.d("UserDao", "user password is " + pass);
  59.                 Log.d("UserDao", "user phone is " + pho);
  60.                 Log.d("UserDao", "user address is " + addr);
  61.             } while (cursor.moveToNext());
  62.         }
  63.         cursor.close();
  64.         return true;
  65.     }
  66.     public boolean isExist(String account) {
  67.         Cursor cursor = db.query("user", null, "account = ?", new String[] {account}, null, null, null);
  68.         return cursor != null && cursor.getCount() > 0;
  69.     }
  70.     public String getPassword(String account) {
  71.         Cursor cursor = db.query("user", null, "account = ?", new String[] {account}, null, null, null);
  72.         cursor.moveToFirst();
  73.         String password = cursor.getString(cursor.getColumnIndex("password"));
  74.         return password;
  75.     }
复制代码
3.启动效果WelcomeActivity.java
  1. package and.yjg.music_app; 
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.os.CountDownTimer;
  5. import android.widget.TextView;
  6. import androidx.appcompat.app.AppCompatActivity;
  7. import Login.LoginActivity;
  8. public class WelcomeActivity extends AppCompatActivity {
  9.     private TextView tvCountdown;
  10.     private CountDownTimer countDownTimer;
  11.     private long timeLeftInMillis = 3000;
  12.     protected void onCreate(Bundle savedInstanceState){
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_welcome);
  15.         tvCountdown = findViewById(R.id.tv_countdown);
  16.         startCountdown();
  17.     }
  18.     private void startCountdown() {
  19.         countDownTimer = new CountDownTimer(timeLeftInMillis,1000){
  20.             public void onTick(long millisUntilFinished){
  21.                 timeLeftInMillis = millisUntilFinished;
  22.                 int secondsRemaining = (int) (millisUntilFinished/1000);
  23.                 tvCountdown.setText(secondsRemaining+"s");
  24.             }
  25.             public void onFinish(){
  26.                 startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
  27.                 finish();
  28.             }
  29.         }.start();
  30.     }
  31. protected  void onDestroy(){
  32.         super.onDestroy();
  33.         if (countDownTimer != null){
  34.             countDownTimer.cancel();
  35.         }
  36.     }
  37. }
复制代码
4.用户登录LoginActivity.java
  1. package Login;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.Toast;
  8. import androidx.appcompat.app.ActionBar;
  9. import androidx.appcompat.app.AppCompatActivity;
  10. import and.yjg.music_app.MainActivity;
  11. import and.yjg.music_app.R;
  12. public class LoginActivity extends AppCompatActivity {
  13.     private Button btn_login;    
  14.     private Button btn_register;
  15.     private EditText et_account;
  16.     private EditText et_password;
  17.     private UserDao dao;        
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.activity_login);
  22.         initView();
  23.     }
  24.     public void initView() {
  25.         ActionBar actionBar = getSupportActionBar();
  26.         if(actionBar != null){
  27.             actionBar.hide();
  28.         }
  29.         btn_login = findViewById(R.id.btn_login);
  30.         btn_register = findViewById(R.id.btn_register);
  31.         et_account = findViewById(R.id.et_account);
  32.         et_password = findViewById(R.id.et_password);
  33.         btn_login.setOnClickListener(new View.OnClickListener() {
  34.             @Override
  35.             public void onClick(View v) {
  36.                 String acc = et_account.getText().toString().trim();
  37.                 String pass = et_password.getText().toString().trim();
  38.                 dao = new UserDao(getApplicationContext());
  39.                 dao.open();
  40.                 if (dao.isExist(acc) == false) {
  41.                     Toast.makeText(LoginActivity.this,"账号不存在,请重新输入!", Toast.LENGTH_SHORT).show();
  42.                 } else {
  43.                     if (dao.getPassword(acc).equals(pass)) {
  44.                         Intent intent = new Intent(LoginActivity.this, MainActivity.class);
  45.                         startActivity(intent);
  46.                         finish();
  47.                     } else {
  48.                         Toast.makeText(LoginActivity.this, "密码错误,请重新输入!", Toast.LENGTH_SHORT).show();
  49.                     }
  50.                 }
  51.                 dao.close();
  52.             }
  53.         });
  54.         btn_register.setOnClickListener(new View.OnClickListener() {
  55.             @Override
  56.             public void onClick(View v) {
  57.                 Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
  58.                 startActivityForResult(intent,1);
  59.             }
  60.         });
  61.     }
  62.     @Override
  63.     protected void onActivityResult(int requestCode, int resultCode, Intent data){
  64.         super.onActivityResult(requestCode, resultCode, data);
  65.         if(data != null){
  66.             if(requestCode == 1 && resultCode == 1){
  67.                 String name = data.getStringExtra("acc");
  68.                 String password = data.getStringExtra("pass");
  69.                 et_account.setText(name);
  70.                 et_password.setText(password);
  71.             }
  72.         }
复制代码
五、各类布局文件
  activity_welcom.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".WelcomeActivity">
  8.     <TextView
  9.         android:id="@+id/tv_countdown"
  10.         android:layout_width="100dp"
  11.         android:layout_height="60dp"
  12.         android:layout_alignParentRight="true"
  13.         android:layout_alignParentBottom="true"
  14.         android:layout_marginRight="6dp"
  15.         android:layout_marginBottom="89dp"
  16.         android:background="@color/Blue"
  17.         android:gravity="center"
  18.         android:text="3s"
  19.         android:textSize="30dp" />
  20.     <ImageView
  21.         android:layout_width="match_parent"
  22.         android:layout_height="wrap_content"
  23.         android:src="@mipmap/action" />
  24. </RelativeLayout>
复制代码
activity_login.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     android:background="@color/White"
  8.     android:orientation="vertical">
  9.     <ImageView
  10.         android:id='@+id/iv'
  11.         android:layout_width="match_parent"
  12.         android:layout_height="30dp"
  13.         android:layout_centerHorizontal="true"
  14.         android:layout_marginTop="0dp"
  15.         android:background="@color/Black"/>
  16.     <LinearLayout
  17.         android:id="@+id/account"
  18.         android:layout_width="match_parent"
  19.         android:layout_height="wrap_content"
  20.         android:layout_below="@id/iv"
  21.         android:layout_centerVertical="true"
  22.         android:layout_marginBottom="5dp"
  23.         android:layout_marginLeft="10dp"
  24.         android:layout_marginRight="10dp"
  25.         android:layout_marginTop="40dp"
  26.         android:orientation="horizontal">
  27.         <TextView
  28.             android:id="@+id/tv_account"
  29.             android:layout_width="wrap_content"
  30.             android:layout_height="wrap_content"
  31.             android:padding="10dp"
  32.             android:text="账 号"
  33.             android:textColor="#000"
  34.             android:background="@drawable/text_style"
  35.             android:textSize="25sp" />
  36.         <View
  37.             android:layout_width="1dp"
  38.             android:layout_height="match_parent"
  39.             android:background="@color/Gray"/>
  40.         <EditText
  41.             android:id="@+id/et_account"
  42.             android:layout_width="match_parent"
  43.             android:layout_height="match_parent"
  44.             android:background="@drawable/edit_style"
  45.             android:hint="请输入账号"
  46.             android:textColor="@color/Gray"
  47.             android:textSize="20sp"
  48.             android:gravity="center"
  49.             android:inputType="text"
  50.             android:padding="10dp" />
  51.     </LinearLayout>
  52.     <LinearLayout
  53.         android:id="@+id/password"
  54.         android:layout_width="match_parent"
  55.         android:layout_height="wrap_content"
  56.         android:layout_below="@+id/account"
  57.         android:layout_centerVertical="true"
  58.         android:layout_marginLeft="10dp"
  59.         android:layout_marginRight="10dp"
  60.         android:orientation="horizontal">
  61.         <TextView
  62.             android:id="@+id/tv_password"
  63.             android:layout_width="wrap_content"
  64.             android:layout_height="wrap_content"
  65.             android:padding="10dp"
  66.             android:text="密 码"
  67.             android:background="@drawable/text_style"
  68.             android:textColor="#000"
  69.             android:textSize="25sp"/>
  70.         <View
  71.             android:layout_width="1dp"
  72.             android:layout_height="match_parent"
  73.             android:background="@color/Gray"/>
  74.         <EditText
  75.             android:id="@+id/et_password"
  76.             android:layout_width="match_parent"
  77.             android:layout_height="match_parent"
  78.             android:layout_toRightOf="@id/tv_password"
  79.             android:hint="请输入密码"
  80.             android:textColor="@color/Gray"
  81.             android:textSize="20sp"
  82.             android:gravity="center"
  83.             android:background="@drawable/edit_style"
  84.             android:inputType="textPassword"
  85.             android:padding="10dp"/>
  86.     </LinearLayout>
  87.     <Button
  88.         android:id="@+id/btn_login"
  89.         android:layout_width="match_parent"
  90.         android:layout_height="wrap_content"
  91.         android:layout_marginTop="40dp"
  92.         android:layout_marginLeft="10dp"
  93.         android:layout_marginRight="10dp"
  94.         android:background="@drawable/button_style"
  95.         android:gravity="center"
  96.         android:text="登录"
  97.         android:textColor="#ffffff"
  98.         android:textSize="30sp"
  99.         android:layout_below="@+id/password"/>
  100.     <Button
  101.         android:id="@+id/btn_register"
  102.         android:layout_width="match_parent"
  103.         android:layout_height="wrap_content"
  104.         android:layout_marginTop="20dp"
  105.         android:layout_marginLeft="10dp"
  106.         android:layout_marginRight="10dp"
  107.         android:background="@drawable/button_style"
  108.         android:gravity="center"
  109.         android:text="注册"
  110.         android:textColor="#ffffff"
  111.         android:textSize="30sp"
  112.         android:layout_below="@+id/btn_login" />
  113. </RelativeLayout>
复制代码
总结:在这次基于Android Studio的音视频播放系统设计与实现的课程设计中,我不仅把握了一系列关键技术和工具,还对整个项目开辟流程有了更深入的理解。:认识并把握了Android Studio的开辟情况,包罗如何设置、配置项目,以及使用内置的工具如模拟器举行测试。深入相识了Android SDK和相关API,特别是与音视频播放相关的部分,如MediaPlayer、VideoView等。
别的,这次实验中,我还碰到一些数据传递中断标题,所以我还查看了一些使用断电调试的方法,也是得我把握了一些关于断点调试的有关用法,这也让我意识到断点调试与良好的代码构造和解释风俗是相辅相成的。一个清晰、有良好解释的代码布局使得断点调试更为有效,因为你可以快速相识每一部分代码的作用和相互关系。
通过这次课程设计,我不仅提高了技术能力,更重要的是学会了如何综合运用这些技术来解决实际标题。
由于篇幅限制,此处就只放了部分代码,实在也还够用,有需要的尽可拿去用。另外在这里附上这个项目的完备代码链接https://download.csdn.net/download/weixin_74924162/89248276​​​​​​
如果有小伙伴想要源码但是又没有会员的可以评论在下方,找我白嫖。
(因为有多篇文章源码,所以最好是在本文章里评论,我能第一时间知道你要的是哪一个源码,同时也可以点赞收藏加评论啥的给卑微的咱增加点微薄的积分吧,就当是报酬了,提前谢过各位看官啦。)
这里分享一个做了页面美化的版本链接给有需要的伙伴:Android studio音频视频播放器课程设计(继上一个项目,这里做了稍许的美化改动以及部分功能的改动)-CSDN博客

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

北冰洋以北

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表