public void run() { while (!terminate) { try { int ret = MS98NativeInterface.ms98Render(buffer, buffer.length); if (ret == 0) { track.stop(); Log.d(TAG, "stream terminated"); MS98NativeInterface.ms98Close(); break; } track.write(buffer, 0, buffer.length); Thread.sleep(WAIT_PER_BLOCK); } catch (InterruptedException e) { // thru } } }
@Override public void onDestroy() { stopSong(); track.release(); MS98NativeInterface.ms98Deinit(); PMDWinNativeInterface.pmdwinDeinit(); super.onDestroy(); }
public synchronized void stopSong() { terminate = true; if (thread == null) return; try { thread.join(); } catch (InterruptedException e) { } thread = null; track.stop(); MS98NativeInterface.ms98Close(); PMDWinNativeInterface.pmdwinClose(); // nm.cancel(NID_PMD_PLAYING); stopForeground(true); }
@Override public void onCreate() { super.onCreate(); Log.d(TAG, "onCreate()"); track = new AudioTrack( AudioManager.STREAM_MUSIC, SAMPLES_PER_SEC, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, TRACK_BUFFER_SIZE, AudioTrack.MODE_STREAM); terminate = false; thread = null; MS98NativeInterface.ms98Init(); PMDWinNativeInterface.pmdwinInit(); }
public synchronized void startSong(String filename) { if (thread != null) stopSong(); this.filename = filename; if (this.filename.toLowerCase().endsWith(".s98")) { if (MS98NativeInterface.ms98OpenFile(filename) != 1) { Log.e(TAG, "Cannot open " + filename + " for playing"); stopSelf(); return; } audioStreamer = audioStreamerS98; } else { if (PMDWinNativeInterface.pmdwinOpenFile(filename) != 1) { Log.e(TAG, "Cannot open " + filename + " for playing"); stopSelf(); return; } audioStreamer = audioStreamerPMDWin; } terminate = false; track.play(); track.write(empty, 0, empty.length); thread = new Thread(audioStreamer); thread.start(); Notification nf = new Notification(R.drawable.ic_launcher, title, System.currentTimeMillis()); nf.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; Intent notificationIntent = new Intent(this, SelectSong.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); nf.setLatestEventInfo(getApplicationContext(), title, title2, contentIntent); // nm.notify(NID_PMD_PLAYING, nf); startForeground(NID_PMD_PLAYING, nf); }