当我传递一个 URL 时,它工作正常(用户单击一个按钮):
final Intent i = new Intent(MusicService.ACTION_URL);
Uri uri = Uri.parse("http://stream-72.shoutcast.com:80/hot108_mp3_128kbps");
i.setData(uri);
startService(i);
但是当用户单击 ListView 项目时,什么也没有发生:
public List<String> songs = new ArrayList<String>();
protected void onListItemClick(ListView l, View v, int position, long id) {
playSong(MEDIA_PATH + songs.get(position));
}
private void playSong(String songPath) {
final Intent i = new Intent(MusicService.ACTION_URL);
Uri uri = Uri.parse(songPath);
i.setData(uri);
startService(i);
}
我已经尝试在其中设置 Toasts MusicService.ACTION_URL
,它永远不会仅在 ListView 场景中被调用,但它在第一个按钮单击场景中会被调用。
我什至尝试在 playSong 方法中创建一个本地 MediaPlayer(在服务之外)并且它工作正常,但我希望 MusicService 来处理播放列表项:
mp.setDataSource(songPath);
请告诉我,我做错了什么?如果您需要更多信息,请告诉我。谢谢。
这是更新的清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Design.streaming"
android:versionCode="56"
android:versionName="1.8.0.2" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:resizeable="true" android:anyDensity="true" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!-- <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature name="android.hardware.touchscreen" required="false" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar" android:debuggable="false">
<activity
android:name=".Main"
android:launchMode="singleTask"
android:configChanges="orientation"
android:label="@string/title_activity_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.paypal.android.MEP.PayPalActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
</activity>
<activity android:name=".Blog" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" />
<activity android:name=".Favs" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" />
<activity android:name=".Songs" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation"/>
<activity android:name=".IcyStreamMeta" />
<activity android:name=".Favorites"> </activity>
<activity android:name=".PizzaMain" />
<activity android:label="@string/app_name" android:name="Info"/>
<activity android:name=".SomafmActivity" android:launchMode="singleTask"
>
<intent-filter>
<action android:name="com.LudwigAppDesign.streamingradioplayerproMain" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".SongsActivity" android:launchMode="singleTask"
/>
<activity android:name=".AncientfmActivity" android:launchMode="singleTask"
/>
<activity android:name=".Pizza"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name">
</activity>
<activity android:name=".ResultDeligate" />
<activity android:name=".AppPreferenceActivity"
android:label="@string/app_name">
<intent-filter>
<action
android:name="net.learn2develop.AppPreferenceActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name=".MusicService"
android:exported="false" >
<intent-filter>
<action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.PLAY" />
<action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.PAUSE" />
<action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.SKIP" />
<action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.REWIND" />
<action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.STOP" />
</intent-filter>
<intent-filter>
<action android:name="com.LudwigAppDesign.streamingradioplayerpro.Main" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.URL" />
<data android:scheme="http" />
<data android:scheme="file" />
</intent-filter>
</service>
<receiver android:name=".MusicIntentReceiver" >
<intent-filter>
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
</application>