学习Android有两个星期了,在网上找了个视频,跟着做了个Mp3项目,功能不全,因为视频要求的歌词是lrc格式的,我用的是酷狗,下载的歌词是krc格式,没有找到合适的反编译的方法,所以歌词同步显示的功能未能实现,希望在这方面有研究的朋友,一同研究一下。
以下是我目前实现的功能,先上代码(布局文件):
1.AndroidManfiest.xml文件
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mp3player" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Mp3Player01Activity" android:label="@string/app_name"/> <activity android:name=".LocalMp3ListActivity" android:label="@string/app_name"/> <activity android:name=".PlayerActivity" android:label="@string/app_name"/> <service android:name=".service.DownloadService"></service> <service android:name=".service.PlayerService"></service> </application> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.INTERNET" /> <!-- 加入访问internet的权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 访问SD卡的权限 --> </manifest>
2.几个布局文件
(1).main.xml
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /> </LinearLayout> </TabHost>
(2.)mp3info_item.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="1dip" android:paddingBottom="1dip" > <TextView android:id="@+id/mp3_name" android:layout_height="30dip" android:layout_width="180dip" android:textSize="10pt"/> <TextView android:id="@+id/mp3_size" android:layout_height="30dip" android:layout_width="180dip" android:textSize="10pt"/> </LinearLayout>
(3.) remote_mp3_list.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical" ></ListView> </LinearLayout>
(4.)local_mp3_list.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/listLinearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical" /> </LinearLayout> </LinearLayout>
(5.)player.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="1dip" android:paddingBottom="1dip"> <TextView android:id="@+id/lrcText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="lrc" /> <ImageButton android:id="@+id/begin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/begin" /> <ImageButton android:id="@+id/pause" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/pause" /> <ImageButton android:id="@+id/stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/stop" /> </LinearLayout>
3.字符串文件:strings.xml文件
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, Mp3PlayerActivity!</string> <string name="app_name">Mp3Player</string> <string name="mp3list.update">更新列表</string> <string name="mp3list.about">关于</string> </resources>