<?xml version="1.0" encoding="UTF-8"?>
<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>ไอเอินบล๊อก &#187; android play music</title>
	<atom:link href="http://www.iearn.in.th/tag/android-play-music/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iearn.in.th</link>
	<description>Just Play and Just Knowledge</description>
	<lastBuildDate>Fri, 05 Aug 2011 15:10:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ฟังเำพลงใน Android กันเถอะ</title>
		<link>http://www.iearn.in.th/2009/01/08/%e0%b8%9f%e0%b8%b1%e0%b8%87%e0%b9%80%e0%b8%b3%e0%b8%9e%e0%b8%a5%e0%b8%87%e0%b9%83%e0%b8%99-android-%e0%b8%81%e0%b8%b1%e0%b8%99%e0%b9%80%e0%b8%96%e0%b8%ad%e0%b8%b0/</link>
		<comments>http://www.iearn.in.th/2009/01/08/%e0%b8%9f%e0%b8%b1%e0%b8%87%e0%b9%80%e0%b8%b3%e0%b8%9e%e0%b8%a5%e0%b8%87%e0%b9%83%e0%b8%99-android-%e0%b8%81%e0%b8%b1%e0%b8%99%e0%b9%80%e0%b8%96%e0%b8%ad%e0%b8%b0/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 18:42:33 +0000</pubDate>
		<dc:creator>nolifelover</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[android audio]]></category>
		<category><![CDATA[android play music]]></category>
		<category><![CDATA[android xml]]></category>
		<category><![CDATA[music player]]></category>

		<guid isPermaLink="false">http://www.iearn.in.th/?p=17</guid>
		<description><![CDATA[ว่างๆ ไม่มีอะไรทำเลยเอาโค้ดสำหรับไว้ฟังเพลงเผื่อว่าใครต้องการเขียนโปรแกรมสำหรับการฟังเพลง หรือการเล่นเสียงใน android ซึ่งผมว่ามันทำได้ง่ายมากเนื่องจา่ก api ที่ให้มาสามารถที่จะทำให้เราเขียนเจ้าโปรแกรมฟังเพลงนี้ได้อย่าง่ายดาย โดยในส่วนี้เป็นโค้ดที่ผมไปหามาจากใน anddev.org ส่วนกระทุ้ไหนผมจำไม่ได้ละเพราะว่าผมเอาโึค้ดมาป่นๆ กันแล้วเขียนเองบ้างลอกเขามาบ้างแต่ยังไงก็ให้ credit anddev.org นะครับเอาเป็นว่าไปดู source กันดีกว่าครับ MusicPlayer.java import java.io.IOException; import android.app.Activity; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; &#160; import com.atm.R; &#160; public class MusicPlayer extends Activity &#123; /** Called when the activity is first created. */ @Override public void [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.iearn.in.th/wp-content/uploads/2009/01/music_player.png"><img class="aligncenter size-medium wp-image-19" title="music_player" src="http://www.iearn.in.th/wp-content/uploads/2009/01/music_player-200x300.png" alt="music_player" width="200" height="300" /></a></p>
<p>ว่างๆ ไม่มีอะไรทำเลยเอาโค้ดสำหรับไว้ฟังเพลงเผื่อว่าใครต้องการเขียนโปรแกรมสำหรับการฟังเพลง หรือการเล่นเสียงใน android ซึ่งผมว่ามันทำได้ง่ายมากเนื่องจา่ก api ที่ให้มาสามารถที่จะทำให้เราเขียนเจ้าโปรแกรมฟังเพลงนี้ได้อย่าง่ายดาย โดยในส่วนี้เป็นโค้ดที่ผมไปหามาจากใน anddev.org ส่วนกระทุ้ไหนผมจำไม่ได้ละเพราะว่าผมเอาโึค้ดมาป่นๆ กันแล้วเขียนเองบ้างลอกเขามาบ้างแต่ยังไงก็ให้ credit anddev.org นะครับเอาเป็นว่าไปดู source กันดีกว่าครับ<br />
<span id="more-17"></span></p>
<blockquote><p>MusicPlayer.java</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.media.MediaPlayer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.media.MediaPlayer.OnCompletionListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View.OnClickListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Button</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.atm.R</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MusicPlayer <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle icicle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>icicle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">music_player</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Find the Button from the xml-file.</span>
		<span style="color: #003399;">Button</span> cmd_play <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">cmd_play</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		cmd_play.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			@Override
			<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> arg0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				MediaPlayer mp <span style="color: #339933;">=</span> MediaPlayer.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>MusicPlayer.<span style="color: #000000; font-weight: bold;">this</span>,
						R.<span style="color: #006633;">raw</span>.<span style="color: #006633;">fish</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
					mp.<span style="color: #006633;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IllegalStateException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
					e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
					e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				mp.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">// i.e. react on the end of the music-file:</span>
				mp.<span style="color: #006633;">setOnCompletionListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> OnCompletionListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #666666; font-style: italic;">// @Override</span>
					<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCompletion<span style="color: #009900;">&#40;</span>MediaPlayer arg0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">// File has ended !!! Wink</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p>music_player.xml</p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:orientation</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Button</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/cmd_play&quot;</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">android:text</span>=<span style="color: #ff0000;">&quot;Play the music !!!&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>หลังจากนั้นก็ทำการเลือกเพลงมาซักเพลงครับ สมมุติว่าเป็น fish.mp3 นะครับ ผมก็ทำการ copy file ไปไว้ที่ raw ครับก็เป็นอันว่าเรียบร้อยสำหรับคนที่เล่นแล้วบอกว่า อ้าว เปิดแล้วไม่มีเสียงมันเสียหรือเปล่า อาจจะเป็นเพราะว่าเรายังไม่ได้ทำการตั้งค่าให้ emulator รู้จักเสียงครับก็ให้เข้่าไปแก้ใน Addition Emulator command line เพิ่มในส่วนนี้ครับ</p>
<blockquote><p>-audio winaudio</p></blockquote>
<p>แค่นี้ก็ฟังเพลงได้แล้วครับ</p>

<p class="sayac_bilgi">63 views</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iearn.in.th/2009/01/08/%e0%b8%9f%e0%b8%b1%e0%b8%87%e0%b9%80%e0%b8%b3%e0%b8%9e%e0%b8%a5%e0%b8%87%e0%b9%83%e0%b8%99-android-%e0%b8%81%e0%b8%b1%e0%b8%99%e0%b9%80%e0%b8%96%e0%b8%ad%e0%b8%b0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

