Note that there are some explanatory texts on larger screens.

plurals
  1. POPass Uri through Intent to MusicService MediaPlayer, from ListView click
    primarykey
    data
    text
    <p>When I pass a URL it works fine (user clicks a button):</p> <pre><code>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); </code></pre> <p>But when the user clicks a ListView item, nothing happens:</p> <pre><code>public List&lt;String&gt; songs = new ArrayList&lt;String&gt;(); 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); } </code></pre> <p>I've tried setting up Toasts in <code>MusicService.ACTION_URL</code> and it never gets called only in the ListView scenario but it does in the first button click scenario. </p> <p>I've even tried creating a local MediaPlayer (outside the Service) inside the playSong method and it works fine, but I want the MusicService to handle playing the list item instead:</p> <pre><code>mp.setDataSource(songPath); </code></pre> <p>Please tell me, what am I doing wrong? If you need more info let me know. Thanks.</p> <p>Here is the UPDATED manifest file:</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.Design.streaming" android:versionCode="56" android:versionName="1.8.0.2" &gt; &lt;uses-sdk android:minSdkVersion="9" android:targetSdkVersion="15" /&gt; &lt;supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:resizeable="true" android:anyDensity="true" /&gt; &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.RECORD_AUDIO"/&gt; &lt;!-- &lt;uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/&gt; --&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt; &lt;uses-feature name="android.hardware.touchscreen" required="false" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar" android:debuggable="false"&gt; &lt;activity android:name=".Main" android:launchMode="singleTask" android:configChanges="orientation" android:label="@string/title_activity_main" android:screenOrientation="portrait" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.paypal.android.MEP.PayPalActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"&gt; &lt;/activity&gt; &lt;activity android:name=".Blog" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" /&gt; &lt;activity android:name=".Favs" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" /&gt; &lt;activity android:name=".Songs" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation"/&gt; &lt;activity android:name=".IcyStreamMeta" /&gt; &lt;activity android:name=".Favorites"&gt; &lt;/activity&gt; &lt;activity android:name=".PizzaMain" /&gt; &lt;activity android:label="@string/app_name" android:name="Info"/&gt; &lt;activity android:name=".SomafmActivity" android:launchMode="singleTask" &gt; &lt;intent-filter&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerproMain" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".SongsActivity" android:launchMode="singleTask" /&gt; &lt;activity android:name=".AncientfmActivity" android:launchMode="singleTask" /&gt; &lt;activity android:name=".Pizza" android:configChanges="keyboardHidden|orientation" android:label="@string/app_name"&gt; &lt;/activity&gt; &lt;activity android:name=".ResultDeligate" /&gt; &lt;activity android:name=".AppPreferenceActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="net.learn2develop.AppPreferenceActivity" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:name=".MusicService" android:exported="false" &gt; &lt;intent-filter&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.PLAY" /&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.PAUSE" /&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.SKIP" /&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.REWIND" /&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.STOP" /&gt; &lt;/intent-filter&gt; &lt;intent-filter&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerpro.Main" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;intent-filter&gt; &lt;action android:name="com.LudwigAppDesign.streamingradioplayerpro.action.URL" /&gt; &lt;data android:scheme="http" /&gt; &lt;data android:scheme="file" /&gt; &lt;/intent-filter&gt; &lt;/service&gt; &lt;receiver android:name=".MusicIntentReceiver" &gt; &lt;intent-filter&gt; &lt;action android:name="android.media.AUDIO_BECOMING_NOISY" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload