<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>sound &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/sound/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Tue, 09 Nov 2010 08:04:45 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>sound &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[HOWTO: Android Audio Widget]]></title>
		<link>https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/</link>
					<comments>https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Tue, 09 Nov 2010 08:04:45 +0000</pubDate>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[NaBloPoMo]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[widget]]></category>
		<guid isPermaLink="false">http://shkspr.mobi/blog/?p=2650</guid>

					<description><![CDATA[I&#039;ve recently released a couple of audio widgets.  Inspired by the Instant Rimshot and Sad Trombone sites, these are &#34;single serving&#34; widget.  For the &#34;Family Fortunes&#34; buzzer widget, you click the icon and you&#039;ll hear the famous &#34;EURGH-ERRRR&#34; noise.  I&#039;m also selling a &#34;Dramatic Sound Effect&#34; Widget - download it by scanning this code.  Go on, it&#039;s a mere 50p!   This is a quick tutorial showing…]]></description>
										<content:encoded><![CDATA[<p>I've recently released a couple of audio widgets.  Inspired by the <a href="http://instantrimshot.com/">Instant Rimshot</a> and <a href="http://www.sadtrombone.com/">Sad Trombone</a> sites, these are "<a href="http://kottke.org/08/02/single-serving-sites">single serving</a>" widget.</p>

<p>For the "Family Fortunes" buzzer widget, you click the icon and you'll hear the famous "EURGH-ERRRR" noise.</p>

<p>I'm also selling a "Dramatic Sound Effect" Widget - download it by scanning this code.  Go on, it's a mere 50p!
<img src="https://shkspr.mobi/blog/wp-content/uploads/2010/11/Dramatic-Widget-QR-Code.png" alt="Dramatic Widget QR Code" title="Dramatic Widget QR Code" width="150" height="150" class="aligncenter size-full wp-image-2857"></p>

<p>This is a quick tutorial showing how to build a sound playing widget in Android.  It assumes you've already set up Eclipse and know how to create your own projects.</p>

<h2 id="the-source-code"><a href="https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/#the-source-code">The Source Code</a></h2>

<p>Here's the main Java source code - with comments.</p>

<pre><code>package mobi.shkspr.android.ButtonWidget;

import mobi.shkspr.android.ButtonWidget.R;

//All the Androidy bits and bobs you need to import.
import android.media.*;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class ButtonWidget extends AppWidgetProvider {
    public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        //First up, the icon. I've created a file called h_yellow_x.png and placed it in /res/drawable
                int drawableResourse = R.drawable.h_yellow_x;
                //Set Up the widget
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
                //Set the image which will appear on the screen
        remoteViews.setImageViewResource(R.id.ImageView01, drawableResourse );
        Intent active = new Intent(context, ButtonWidget.class);
        active.setAction(ACTION_WIDGET_RECEIVER);
        PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
        remoteViews.setOnClickPendingIntent(R.id.ImageView01, actionPendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // v1.5 fix that doesn't call onDelete Action
        final String action = intent.getAction();
        if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
            //The widget is being deleted off the desktop
            final int appWidgetId = intent.getExtras().getInt(
                    AppWidgetManager.EXTRA_APPWIDGET_ID,
                    AppWidgetManager.INVALID_APPWIDGET_ID);
            if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
                this.onDeleted(context, new int[] { appWidgetId });
            }
        } else {
            // check, if our Action was called
            if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {

                //Play the audio file
                                //The audio file is in /res/raw/ and is an OGG file
                MediaPlayer mPlay = MediaPlayer.create(context, R.raw.ff);
                mPlay.start();
            } else {
                // do nothing
            }


            super.onReceive(context, intent);
        }
    }
}

</code></pre>

<p>Also</p>

<h2 id="the-manifest"><a href="https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/#the-manifest">The Manifest</a></h2>

<p>The XML you'll need to get everything configured.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mobi.shkspr.android.ButtonWidget"
    android:versionCode="1"
    android:versionName="1.0"&gt;

    &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;

        &lt;!-- Broadcast Receiver that will process AppWidget updates --&gt;
        &lt;receiver android:name=".ButtonWidget" android:label="@string/app_name"&gt;
            &lt;intent -filter&gt;
                &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
                &lt;!-- Broadcast Receiver that will also process our self created action --&gt;
                &lt;action android:name="my.package.name.ButtonWidget.ACTION_WIDGET_RECEIVER"/&gt;
            &lt;/intent&gt;
            &lt;meta -data android:name="android.appwidget.provider" android:resource="@xml/widget_def" /&gt;
        &lt;/receiver&gt;

    &lt;/application&gt;

    &lt;uses -sdk android:minSdkVersion="3" /&gt;
&lt;/manifest&gt;
</code></pre>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=2650&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2010/11/howto-android-audio-widget/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
