低價(jià)網(wǎng)站建設(shè)方案seo查詢工具有哪些
這個(gè)項(xiàng)目適合剛剛學(xué)習(xí)Android studio的初學(xué)者,實(shí)現(xiàn)音視頻的基本播放功能,各項(xiàng)功能的頁(yè)面都做的比較簡(jiǎn)單,特別適用于初學(xué)者,其特點(diǎn)在于本項(xiàng)目拋開了各種花里胡哨的制作,以最接近初學(xué)者的樣式畫面呈現(xiàn),完全不用擔(dān)心被質(zhì)疑套用別人的項(xiàng)目,要是實(shí)在追求完美的話,本文末尾也附上了經(jīng)過美化后的相同項(xiàng)目鏈接。
基于Android Studio的音視頻播放系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)
一、問題描述
音視頻播放系統(tǒng)包括:使用sqlite創(chuàng)建數(shù)據(jù)庫(kù)用于存儲(chǔ)用戶信息、啟動(dòng)效果、用戶注冊(cè)、用戶登錄、顯示用戶信息、音樂播放、視頻播放等功能。
二、功能描述
設(shè)計(jì)一個(gè)音視頻播放器app,使之能夠?qū)崿F(xiàn)以下功能:
- 創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)用于存儲(chǔ)用戶信息。
- 啟動(dòng)效果:該App設(shè)計(jì)了啟動(dòng)頁(yè)面,啟動(dòng)后倒計(jì)時(shí)3s后可進(jìn)入app。
- 用戶登錄注冊(cè):該App提供用戶登錄和注冊(cè)功能,用戶可以創(chuàng)建新賬戶或使用現(xiàn)有賬戶登錄。當(dāng)用戶注冊(cè)完成后跳轉(zhuǎn)回到登錄頁(yè)面進(jìn)行用戶登錄。用戶需要提供有效的用戶名和密碼進(jìn)行身份驗(yàn)證。
- 顯示用戶信息:用戶登錄后可點(diǎn)擊信息按鈕查看用戶信息,包括歷史登錄用戶的用戶信息。
- 音樂播放功能:用戶登錄后,可以通過該App瀏覽和播放音樂文件。App提供音樂列表,用戶可以瀏覽并選擇要播放的音樂。點(diǎn)擊音樂后,將跳轉(zhuǎn)到音樂播放頁(yè)面,可進(jìn)行音樂的播放、暫停、上一曲和下一曲以及拖動(dòng)進(jìn)度條來控制音樂播放。
- ?視頻播放功能:該App還提供視頻播放功能。用戶可以通過App瀏覽并選擇要播放的視頻文件。點(diǎn)擊視頻后,跳轉(zhuǎn)到音樂播放頁(yè)面,可以控制視頻播放和暫停。
三、功能實(shí)現(xiàn)
項(xiàng)目目錄:
?1.創(chuàng)建數(shù)據(jù)庫(kù),建立一個(gè)用戶表,表結(jié)構(gòu)如下:
2.實(shí)現(xiàn)app啟動(dòng)頁(yè)面,頁(yè)面效果如下:
?3.實(shí)現(xiàn)用戶登錄功能,用戶需要提供有效的用戶名和密碼,否側(cè)提示用戶名無效或密碼無效:
4.實(shí)現(xiàn)用戶注冊(cè)功能,點(diǎn)擊注冊(cè)按鈕跳轉(zhuǎn)至用戶注冊(cè)頁(yè)面,用戶注冊(cè)成功跳轉(zhuǎn)回用戶登錄頁(yè)面進(jìn)行用戶登錄:
5.顯示歷史登錄用戶信息功能,登錄成功后,點(diǎn)擊信息后,跳轉(zhuǎn)至用戶信息顯示界面,用戶可查看歷史登錄用戶信息。
6.實(shí)現(xiàn)音樂播放功能,登錄成功后,默認(rèn)顯示音樂列表,點(diǎn)擊音樂后,跳轉(zhuǎn)至音樂播放界面,用戶可通過點(diǎn)擊播放按鈕進(jìn)行音樂的播放、暫停、上一曲和下一曲操作,同時(shí)用戶也可以通過拖動(dòng)進(jìn)度條控制音樂的播放進(jìn)度:
7.實(shí)現(xiàn)視頻播放功能,在默認(rèn)頁(yè)面點(diǎn)擊視頻按鈕后,跳轉(zhuǎn)至視頻列表,點(diǎn)擊視頻可進(jìn)入視頻播放頁(yè)面,用戶可通過點(diǎn)擊播放、暫停、繼續(xù)播放按鈕對(duì)視頻進(jìn)行播放控制。
四、源代碼
1.用戶類定義User.java
package and.yjg.music_app.Login;
public class User {public User() {}public User(String account, String password, String phone, String address) {this.account = account;this.password = password;this.phone = phone;this.address = address;}public String account;public String password;public String phone;public String address;public String getAccount() {return account;}public void setAccount(String account) {this.account = account;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public void setPhone(String phone) {this.phone = phone;}public void setAddress(String address){this.address = address;}public String toString () {return "用戶名:" + account + "\n" +"密碼:" + password + "\n?" +"電話:" + phone + "\n?" +"地址:" + address + "\n";}}
2.UserDao.java
package and.yjg.music_app.Login;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.util.Log;
import and.yjg.music_app.DataBaseHelper;
public class UserDao {private Context context; ??????private DataBaseHelper dbHelper;private SQLiteDatabase db; ??public UserDao(Context context) {this.context = context;}public void open() throws SQLiteException {dbHelper = new DataBaseHelper(context);try {db = dbHelper.getWritableDatabase();} catch (SQLiteException exception) {db = dbHelper.getReadableDatabase();}}public void close() {if (db != null) {db.close();db = null;}}public void addUser(User user) {ContentValues values = new ContentValues();values.put("account", user.account);values.put("password", user.password);values.put("phone", user.phone);values.put("address", user.address);db.insert("user", null, values);}public void deleteUser(User user) {db.delete("user", "account = ?", new String[]{user.account});}public void update(User user) {ContentValues values = new ContentValues();values.put("password", user.password);db.update("user", values, "account = ?", new String[]{user.account});}public boolean find(User user) {Cursor cursor = db.query("user", null, "account = ?", new String[]{user.account}, null, null, null);if (cursor == null || cursor.getCount() < 1) {return false;}if (cursor.moveToFirst()) {do {String acc = cursor.getString(cursor.getColumnIndex("account"));String pass = cursor.getString(cursor.getColumnIndex("password"));String pho = cursor.getString(cursor.getColumnIndex("phone"));String addr = cursor.getString(cursor.getColumnIndex("address"));Log.d("UserDao", "user account is" + acc);Log.d("UserDao", "user password is " + pass);Log.d("UserDao", "user phone is " + pho);Log.d("UserDao", "user address is " + addr);} while (cursor.moveToNext());}cursor.close();return true;}public boolean isExist(String account) {Cursor cursor = db.query("user", null, "account = ?", new String[] {account}, null, null, null);return cursor != null && cursor.getCount() > 0;}public String getPassword(String account) {Cursor cursor = db.query("user", null, "account = ?", new String[] {account}, null, null, null);cursor.moveToFirst();String password = cursor.getString(cursor.getColumnIndex("password"));return password;}
3.啟動(dòng)效果WelcomeActivity.java
package and.yjg.music_app;?
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import Login.LoginActivity;
public class WelcomeActivity extends AppCompatActivity {private TextView tvCountdown;private CountDownTimer countDownTimer;private long timeLeftInMillis = 3000;protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_welcome);tvCountdown = findViewById(R.id.tv_countdown);startCountdown();}private void startCountdown() {countDownTimer = new CountDownTimer(timeLeftInMillis,1000){public void onTick(long millisUntilFinished){timeLeftInMillis = millisUntilFinished;int secondsRemaining = (int) (millisUntilFinished/1000);tvCountdown.setText(secondsRemaining+"s");}public void onFinish(){startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));finish();}}.start();}
protected ?void onDestroy(){super.onDestroy();if (countDownTimer != null){countDownTimer.cancel();}}
}
4.用戶登錄LoginActivity.java
package Login;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import and.yjg.music_app.MainActivity;
import and.yjg.music_app.R;
public class LoginActivity extends AppCompatActivity {private Button btn_login; ???private Button btn_register;private EditText et_account;private EditText et_password;private UserDao dao; ???????@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_login);initView();}public void initView() {ActionBar actionBar = getSupportActionBar();if(actionBar != null){actionBar.hide();}btn_login = findViewById(R.id.btn_login);btn_register = findViewById(R.id.btn_register);et_account = findViewById(R.id.et_account);et_password = findViewById(R.id.et_password);btn_login.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String acc = et_account.getText().toString().trim();String pass = et_password.getText().toString().trim();dao = new UserDao(getApplicationContext());dao.open();if (dao.isExist(acc) == false) {Toast.makeText(LoginActivity.this,"賬號(hào)不存在,請(qǐng)重新輸入!", Toast.LENGTH_SHORT).show();} else {if (dao.getPassword(acc).equals(pass)) {Intent intent = new Intent(LoginActivity.this, MainActivity.class);startActivity(intent);finish();} else {Toast.makeText(LoginActivity.this, "密碼錯(cuò)誤,請(qǐng)重新輸入!", Toast.LENGTH_SHORT).show();}}dao.close();}});btn_register.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);startActivityForResult(intent,1);}});}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data){super.onActivityResult(requestCode, resultCode, data);if(data != null){if(requestCode == 1 && resultCode == 1){String name = data.getStringExtra("acc");String password = data.getStringExtra("pass");et_account.setText(name);et_password.setText(password);}}
五、各類布局文件
??activity_welcom.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".WelcomeActivity"><TextViewandroid:id="@+id/tv_countdown"android:layout_width="100dp"android:layout_height="60dp"android:layout_alignParentRight="true"android:layout_alignParentBottom="true"android:layout_marginRight="6dp"android:layout_marginBottom="89dp"android:background="@color/Blue"android:gravity="center"android:text="3s"android:textSize="30dp" /><ImageViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:src="@mipmap/action" />
</RelativeLayout>
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/White"android:orientation="vertical"><ImageViewandroid:id='@+id/iv'android:layout_width="match_parent"android:layout_height="30dp"android:layout_centerHorizontal="true"android:layout_marginTop="0dp"android:background="@color/Black"/><LinearLayoutandroid:id="@+id/account"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@id/iv"android:layout_centerVertical="true"android:layout_marginBottom="5dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="40dp"android:orientation="horizontal"><TextViewandroid:id="@+id/tv_account"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="賬 號(hào)"android:textColor="#000"android:background="@drawable/text_style"android:textSize="25sp" /><Viewandroid:layout_width="1dp"android:layout_height="match_parent"android:background="@color/Gray"/><EditTextandroid:id="@+id/et_account"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/edit_style"android:hint="請(qǐng)輸入賬號(hào)"android:textColor="@color/Gray"android:textSize="20sp"android:gravity="center"android:inputType="text"android:padding="10dp" /></LinearLayout><LinearLayoutandroid:id="@+id/password"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@+id/account"android:layout_centerVertical="true"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:orientation="horizontal"><TextViewandroid:id="@+id/tv_password"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:text="密 碼"android:background="@drawable/text_style"android:textColor="#000"android:textSize="25sp"/><Viewandroid:layout_width="1dp"android:layout_height="match_parent"android:background="@color/Gray"/><EditTextandroid:id="@+id/et_password"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_toRightOf="@id/tv_password"android:hint="請(qǐng)輸入密碼"android:textColor="@color/Gray"android:textSize="20sp"android:gravity="center"android:background="@drawable/edit_style"android:inputType="textPassword"android:padding="10dp"/></LinearLayout><Buttonandroid:id="@+id/btn_login"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="40dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="@drawable/button_style"android:gravity="center"android:text="登錄"android:textColor="#ffffff"android:textSize="30sp"android:layout_below="@+id/password"/><Buttonandroid:id="@+id/btn_register"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="@drawable/button_style"android:gravity="center"android:text="注冊(cè)"android:textColor="#ffffff"android:textSize="30sp"android:layout_below="@+id/btn_login" />
</RelativeLayout>
總結(jié):在這次基于Android Studio的音視頻播放系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)的課程設(shè)計(jì)中,我不僅掌握了一系列關(guān)鍵技術(shù)和工具,還對(duì)整個(gè)項(xiàng)目開發(fā)流程有了更深入的理解。:熟悉并掌握了Android Studio的開發(fā)環(huán)境,包括如何設(shè)置、配置項(xiàng)目,以及使用內(nèi)置的工具如模擬器進(jìn)行測(cè)試。深入了解了Android SDK和相關(guān)API,特別是與音視頻播放相關(guān)的部分,如MediaPlayer、VideoView等。
此外,這次實(shí)驗(yàn)中,我還遇到一些數(shù)據(jù)傳遞中斷問題,所以我還查看了一些使用斷電調(diào)試的方法,也是得我掌握了一些關(guān)于斷點(diǎn)調(diào)試的有關(guān)用法,這也讓我意識(shí)到斷點(diǎn)調(diào)試與良好的代碼組織和注釋習(xí)慣是相輔相成的。一個(gè)清晰、有良好注釋的代碼結(jié)構(gòu)使得斷點(diǎn)調(diào)試更為有效,因?yàn)槟憧梢钥焖倭私饷恳徊糠执a的作用和相互關(guān)系。
通過這次課程設(shè)計(jì),我不僅提高了技術(shù)能力,更重要的是學(xué)會(huì)了如何綜合運(yùn)用這些技術(shù)來解決實(shí)際問題。
由于篇幅限制,此處就只放了部分代碼,其實(shí)也還夠用,有需要的盡可拿去用。另外在這里附上這個(gè)項(xiàng)目的完整代碼鏈接https://download.csdn.net/download/weixin_74924162/89248276??????。
這里分享一個(gè)做了頁(yè)面美化的版本鏈接給有需要的伙伴:Android studio音頻視頻播放器課程設(shè)計(jì)(繼上一個(gè)項(xiàng)目,這里做了稍許的美化改動(dòng)以及部分功能的改動(dòng))-CSDN博客