Example usage for android.media AudioManager STREAM_MUSIC

List of usage examples for android.media AudioManager STREAM_MUSIC

Introduction

In this page you can find the example usage for android.media AudioManager STREAM_MUSIC.

Prototype

int STREAM_MUSIC

To view the source code for android.media AudioManager STREAM_MUSIC.

Click Source Link

Document

Used to identify the volume of audio streams for music playback

Usage

From source file:com.ibm.watson.developer_cloud.android.text_to_speech.v1.TTSUtility.java

private void initPlayer() {
    stopTtsPlayer();/*from   w w  w  .  jav  a2  s .  c om*/
    // IMPORTANT: minimum required buffer size for the successful creation of an AudioTrack instance in streaming mode.
    int bufferSize = AudioTrack.getMinBufferSize(sampleRate, AudioFormat.CHANNEL_OUT_MONO,
            AudioFormat.ENCODING_PCM_16BIT);

    synchronized (this) {
        audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM);
        if (audioTrack != null)
            audioTrack.play();
    }
}

From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java

/** Called when the activity is first created. */
@SuppressLint("NewApi")
@Override//from  w  w  w .  j a v  a 2s .  c  o m
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    /* pressing volume up/down should cause music volume changes */
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    this.setTitle(this.getActivityTitle());

    /*  
     *   this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml
     *   If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse.
     *   You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place.
     *   Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    kmlFile = getIntent().getData();

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE,
                        android.Manifest.permission.CAMERA, android.Manifest.permission.ACCESS_FINE_LOCATION },
                101);
    } else {
        try {
            this.setContentView(this.getContentViewId());
            initArView();
        } catch (Exception rex) {
            this.architectView = null;
            AbstractArchitectCamActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(AbstractArchitectCamActivity.this, "AR not supported by this device.",
                            Toast.LENGTH_LONG).show();
                }
            });
            Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex);
            finish();
        }
    }

}

From source file:com.example.shyam.popi.LearnEmotions.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    getMenuInflater().inflate(R.menu.activity_screen_slide, menu);

    menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

    // Add either a "next" or "finish" button to the action bar, depending on which page
    // is currently selected.
    MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
            (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish
                    : R.string.action_next);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    return true;/*  w ww . ja v  a 2  s . c  o m*/
}

From source file:fi.mikuz.boarder.gui.internet.DownloadBoard.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.internet_download_board);
    setProgressBarIndeterminateVisibility(true);

    mWaitDialog = new TimeoutProgressDialog(DownloadBoard.this, "Waiting for response", TAG, true);

    Bundle extras = getIntent().getExtras();
    mAction = extras.getInt(DownloadBoard.SHOW_KEY);

    if (mAction == SHOW_INTERNET_BOARD) {
        mBoardId = extras.getInt(InternetMenu.BOARD_ID_KEY);
        mLoggedIn = extras.getBoolean(DownloadBoardList.LOGGED_IN_KEY);

        if (mLoggedIn) {
            mUserId = extras.getString(InternetMenu.USER_ID_KEY);
            mSessionToken = extras.getString(InternetMenu.SESSION_TOKEN_KEY);
        }//from  w ww  . j a v  a  2s. c  om

        getBoard();
    } else if (mAction == SHOW_PREVIEW_BOARD) {
        mLoggedIn = false;

        XStream xstream = new XStream();
        JSONObject fakeMessage = (JSONObject) xstream.fromXML(extras.getString(DownloadBoard.JSON_KEY));
        String fakeMessageString = fakeMessage.toString();

        try {

            if (GlobalSettings.getSensitiveLogging())
                Log.v(TAG, "Got a preview: " + fakeMessageString);
            ConnectionSuccessfulResponse fakeResponse = new ConnectionSuccessfulResponse(
                    new JSONObject(fakeMessageString), InternetMenu.mGetBoardURL);
            onConnectionSuccessful(fakeResponse);
        } catch (JSONException e) {
            Log.e(TAG, "Error reading fake json message", e);
        }
    } else {
        throw new IllegalArgumentException("No proper action defined, action: " + mAction);
    }

}

From source file:org.amahi.anywhere.tv.fragment.TvPlaybackAudioFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setFadingEnabled(false);/*from   www. j  a  va 2s . c om*/

    setBackgroundType(BG_DARK);

    setUpInjections();

    mHandler = new Handler(Looper.getMainLooper());

    setUpRows();

    getAllAudioFiles();

    AudioMetadataRetrievingTask.newInstance(getActivity(), getFileUri(), getAudioFile()).execute();

    mediaPlayer = new MediaPlayer();

    mediaPlayer.setOnCompletionListener(mp -> skipNext());

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    setDataSource();

    prepareAudio();

    mediaPlayer.start();

    setOnItemViewClickedListener((OnItemViewClickedListener) (itemViewHolder, item, rowViewHolder, row) -> {
        if (item instanceof ServerFile) {
            ServerFile serverFile = (ServerFile) item;
            replaceFragment(serverFile);
        }
    });
}

From source file:fi.mikuz.boarder.gui.internet.DownloadBoardList.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_download);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mViewPager = (ViewPager) findViewById(R.id.viewPager);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from  ww w  .  ja  v  a2s.  com*/
        public void onPageSelected(int position) {
            setPageTitle(position + 1);
        }
    });

    setNewViewPager();
    mSearch = (EditText) findViewById(R.id.searchInput);
    mCurrentSearch = "";
    ImageView refresh = (ImageView) findViewById(R.id.refresh);

    Button orderByDate = (Button) findViewById(R.id.orderByDate);
    Button orderByRate = (Button) findViewById(R.id.orderByRate);
    mOrderRule = ORDER_RULE_CHANGE_TIME;
    mOrderDirection = ORDER_DIRECTION_DESCENDING;
    mMaxResults = 40;

    Bundle extras = getIntent().getExtras();
    if (extras.getSerializable(InternetMenu.LOGIN_KEY) != null) {
        @SuppressWarnings("unchecked")
        HashMap<String, String> lastSession = (HashMap<String, String>) extras
                .getSerializable(InternetMenu.LOGIN_KEY);

        mLoggedIn = true;
        mUserId = lastSession.get(InternetMenu.USER_ID_KEY);
        mSessionToken = lastSession.get(InternetMenu.SESSION_TOKEN_KEY);
    }

    mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) {
            String search = mSearch.getText().toString();
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    && !search.equals(mCurrentSearch)) {
                mCurrentSearch = search;
                setNewViewPager();
            }
            return true;
        }
    });

    refresh.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            refreshViewPager();
        }
    });

    orderByDate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mOrderRule.equals(ORDER_RULE_CHANGE_TIME)
                    && mOrderDirection.equals(ORDER_DIRECTION_DESCENDING)) {
                mOrderDirection = ORDER_DIRECTION_ASCENDING;
            } else {
                mOrderRule = ORDER_RULE_CHANGE_TIME;
                mOrderDirection = ORDER_DIRECTION_DESCENDING;
            }
            setNewViewPager();
        }
    });

    orderByRate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mOrderRule.equals(ORDER_RULE_BOARD_RATING)
                    && mOrderDirection.equals(ORDER_DIRECTION_DESCENDING)) {
                mOrderDirection = ORDER_DIRECTION_ASCENDING;
            } else {
                mOrderRule = ORDER_RULE_BOARD_RATING;
                mOrderDirection = ORDER_DIRECTION_DESCENDING;
            }
            setNewViewPager();
        }
    });

}

From source file:com.cyanogenmod.effem.FmRadio.java

/**
 * Required method from parent class//from ww w  .  ja v  a 2  s . c  om
 *
 * @param icicle - The previous instance of this app
 */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    context = getApplicationContext();
    setContentView(R.layout.main);

    // restore preferences
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    mSelectedBand = settings.getInt("selectedBand", 1);
    mCurrentFrequency = settings.getInt("currentFrequency", 0);
    if (context.getResources().getBoolean(R.bool.speaker_supported)) {
        mSelectedOutput = settings.getInt("selectedOutput", 0) > 0 ? 1 : 0;
    }

    // misc setup
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // worker thread for async execution of FM stuff
    mWorker = new HandlerThread("EffemWorker");
    mWorker.start();
    mWorkerHandler = new Handler(mWorker.getLooper());

    // ui preparations
    setupButtons();
}

From source file:com.customprogrammingsolutions.MediaStreamer.MediaStreamerService.java

private void play() {
    Log.i(TAG, "MediaStreamerService.play()");

    isPreparing = true;/*from  w  ww.  j a v a  2s  . co m*/
    startNotification();

    if (!requestAudioFocus()) {
        Log.i(TAG, "MediaStreamerService.play() - AudioFocus request denied");

        notifyStreamError(AUDIO_FOCUS_DENIED_ERROR);
    }

    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setOnErrorListener(this);
    mMediaPlayer.setOnPreparedListener(this);

    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setVolume(1.0f, 1.0f);
    try {
        mMediaPlayer.setDataSource(this, Uri.parse(urlToStream));
    } catch (Exception e) {
        Log.e(TAG, "MediaStreamerService.play() - Error setting data source for the media player", e);
        stop();
        notifyStreamError(MEDIA_PLAYER_ERROR);
        return;
    }
    try {
        mMediaPlayer.prepareAsync(); // prepare async to not block main thread
    } catch (Exception e) {
        Log.e(TAG, "MediaStreamerService.play() - Error preparing the media player", e);
        stop();
        notifyStreamError(MEDIA_PLAYER_ERROR);
        return;
    }

}

From source file:com.zuluindia.watchpresenter.MonitorVolumeKeyPress.java

public void onCreate() {
    super.onCreate();
    settings = getSharedPreferences(Constants.SETTINGS_NAME, MODE_PRIVATE);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    Log.d(LOGCAT, "Service Started!");
    objPlayer = MediaPlayer.create(this, com.zuluindia.watchpresenter.R.raw.silence);
    objPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    objPlayer.setLooping(true);//from  www. j a  va  2  s  . c om
    timer = new Timer();
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    midVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 2;
    resetVolume();
}

From source file:com.zuluindia.watchpresenter.MonitorVolumeKeyPress.java

private void resetVolume() {
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, midVolume, 0);
}