音乐播放器从0到读取手机内的音乐文件——Android Studio小白实训笔记

本文是作者在Android Studio实训中创建简易音乐播放器的笔记,详细记录了从建立Activity、Fragment到读取手机音乐文件的过程。在LocalFragment中,实现了针对Android 6.0以下版本的音乐文件读取,并讨论了如何为Android 6.0及以上版本获取权限。此外,还涵盖了Fragment与Activity间的跳转和传值操作。
摘要由CSDN通过智能技术生成

前言:

小白的我在经历了两周的Android Studio实训课的学习后,编辑了简易音乐播放器的半成品,通过两周的学习让我对打码又激起了兴趣,很感谢实训老师江哥(博客ID:3052world)的悉心教导,下面我将在我两周学习分享给大家。

正文:

  1. 建立Activity,给它布局。
    下面是我的布局代码:
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:background="#fd3131">
        <TextView
            android:id="@+id/main_local_tv"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:text="本地音乐"
            android:textStyle="bold"
            android:textSize="20sp"
            android:textColor="#000"
            android:gravity="center" />
        <TextView
            android:id="@+id/main_online_tv"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:text="在线音乐"
            android:textStyle="bold"
            android:textSize="20sp"
            android:textColor="#000"
            android:gravity="center" />
    </LinearLayout>
//ViewPager是使视图滑动。
<android.support.v4.view.ViewPager
    android:id="@+id/main_vp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>

如图示:
这里写图片描述

2.建立Fragment,布局
为了实现滑动,这里建立了两个Fragment,LocalFragment和OnlineFragment。
LocalFragment里的布局代码为:

//
<ListView
    android:id="@+id/local_listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</ListView>

图示:这里写图片描述
OnlineFragment里放置一个文本就行。
3.给LocalFragment建立适配器adapter(MusicListAdapter和)和实体类entity(Music)。
适配器MusicListAdapter代码:

public class MusicListAdapter extends BaseAdapter {
   //继承BaseAdapter
    private Context context;
    private List<Music> musicList;
public MusicListAdapter(List<Music> musicList,Context context){
    this.context=context;
    this.musicList=musicList;
}
    @Override
    public int getCount() {
        return musicList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值