List of usage examples for android.media MediaPlayer create
public static MediaPlayer create(Context context, int resid)
From source file:projects.oss2015.cs.fundookid.Shoes.java
public void onClickBlueBoot(View view) { if (mpCheer.isPlaying() || mpCheer.isLooping()) { mpCheer.stop();/*from w ww . j av a 2s.c om*/ mpCheer = MediaPlayer.create(this, R.raw.cheering); } mpAww.start(); }
From source file:projects.oss2015.cs.fundookid.Shoes.java
public void onClickRedBoot(View view) { if (mpAww.isPlaying() || mpAww.isLooping()) { mpAww.stop();/* w ww . j av a 2 s . c o m*/ mpAww = MediaPlayer.create(this, R.raw.aww); } mpCheer.start(); }
From source file:com.lamcreations.scaffold.common.activities.VideoSplashScreenActivity.java
@Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { Surface s = new Surface(surface); try {//from w w w. j av a2s . c o m mMediaPlayer = MediaPlayer.create(this, getVideoRawResId()); mMediaPlayer.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT); mMediaPlayer.setSurface(s); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); mMediaPlayer.setOnSeekCompleteListener(this); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mTextureView.setAspectRatio(mMediaPlayer.getVideoWidth(), mMediaPlayer.getVideoHeight()); } catch (IllegalArgumentException | SecurityException | IllegalStateException e) { Log.d(TAG, e.getMessage()); } }
From source file:u.ready_wisc.MenuActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mainmenu);//from w w w . ja va 2s .co m Pushbots.sharedInstance().init(this); // was added for pushbots // RSS activity isn't called if device has no network connection if ((savedInstanceState == null) && isOnline()) { addRssFragment(); } context = getApplicationContext(); pm = context.getPackageManager(); mp = MediaPlayer.create(context, R.raw.sos_sound); disasterButton = (Button) findViewById(R.id.typeDisasterButton); resourcesbutton = (Button) findViewById(R.id.disasterResourcesButton); reportButton = (Button) findViewById(R.id.reportDamageButton); checklistButton = (Button) findViewById(R.id.prepareButton); prepareMenuButton = (ImageButton) findViewById(R.id.prepareMenuButton); emergMenuButton = (ImageButton) findViewById(R.id.emergencyMenuButton); sosMenuButton = (ImageButton) findViewById(R.id.SOSMenubutton); flashlightButton = (ImageButton) findViewById(R.id.FlashlightMenuButton); disasterButton.setOnClickListener(this); flashlightButton.setOnClickListener(this); reportButton.setOnClickListener(this); checklistButton.setOnClickListener(this); prepareMenuButton.setOnClickListener(this); emergMenuButton.setOnClickListener(this); sosMenuButton.setOnClickListener(this); resourcesbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MenuActivity.this, ResourcesActivity.class); MenuActivity.this.startActivity(i); } }); reportButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MenuActivity.this, Emergency.class); MenuActivity.this.startActivity(i); } }); disasterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MenuActivity.this, DisastersType.class); MenuActivity.this.startActivity(i); } }); checklistButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MenuActivity.this, Prep_Main.class); startActivity(i); } }); }
From source file:com.crackingbits.bummer.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EventBus.getInstance().register(this); setContentView(R.layout.activity_main); ButterKnife.bind(this); config = getConfig();/*w ww . jav a 2s .c om*/ hackSound = MediaPlayer.create(this, R.raw.hack); aplauseSound = MediaPlayer.create(this, R.raw.claps); getFreshDesk(); getJenkinsJobs(); fetchData(); if (config.getIsFirstLaunch()) { showMainFragment(); showSettingsFragment(); config.setIsFirstLaunch(false); } else { showMainFragment(); } }
From source file:projects.oss2015.cs.fundookid.Shoes.java
public void onClickYellowBoot(View view) { if (mpCheer.isPlaying() || mpCheer.isLooping()) { mpCheer.stop();/*from www .ja v a 2s. com*/ mpCheer = MediaPlayer.create(this, R.raw.cheering); } mpAww.start(); }
From source file:es.deustotech.piramide.utils.tts.TextToSpeechWeb.java
private static synchronized void speech(final Context context, final String text, final String language) { executor.submit(new Runnable() { @Override//w ww . j a va 2 s .c o m public void run() { try { final String encodedUrl = Constants.URL + language + "&q=" + URLEncoder.encode(text, Encoding.UTF_8.name()); final DefaultHttpClient client = new DefaultHttpClient(); HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.content-charset", "UTF-8"); client.setParams(params); final FileOutputStream fos = context.openFileOutput(Constants.MP3_FILE, Context.MODE_WORLD_READABLE); try { try { final HttpResponse response = client.execute(new HttpGet(encodedUrl)); downloadFile(response, fos); } finally { fos.close(); } final String filePath = context.getFilesDir().getAbsolutePath() + "/" + Constants.MP3_FILE; final MediaPlayer player = MediaPlayer.create(context.getApplicationContext(), Uri.fromFile(new File(filePath))); player.start(); Thread.sleep(player.getDuration()); while (player.isPlaying()) { Thread.sleep(100); } player.stop(); } finally { context.deleteFile(Constants.MP3_FILE); } } catch (InterruptedException ie) { // ok } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:itesm.mx.golpedecalor.MonitoringActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_monitoring); alerta = false;/* w ww . j a v a 2 s. co m*/ dbo = new DataBaseOperations(getApplicationContext()); groupId = getIntent().getLongExtra("id", 0); // Referencias a objetos de interfacae tablaTL = (TableLayout) findViewById(R.id.tablaTL); nombreTV = (TextView) findViewById(R.id.nombreTV); causaTV = (TextView) findViewById(R.id.causaTV); parametroTV = (TextView) findViewById(R.id.parametroTV); switcherVS = (ViewSwitcher) findViewById(R.id.switcherVS); mp = MediaPlayer.create(this, R.raw.alert); recomendacionesTV = (TextView) findViewById(R.id.recomendacionesTV); // Inicializacin rc = new ArrayList<TextView>(); temp = new ArrayList<TextView>(); rad = new ArrayList<TextView>(); try { dbo.open(); } catch (SQLException ex) { Log.e("", ex.toString()); } grupo = dbo.getGroup(groupId); grupo.setIntegrantes(dbo.getAllUsersFromGroup(grupo)); monitoreoHelper = new Monitoreo(grupo, this); for (Usuario u : grupo.getIntegrantes()) { TableRow tr = new TableRow(this); tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT)); TextView tvAux = new TextView(this); tvAux.setText(u.getNombre() + " " + u.getApellidos()); tvAux.setLayoutParams(new TableRow.LayoutParams(400, TableRow.LayoutParams.WRAP_CONTENT)); TextView rcAux = new TextView(this); rcAux.setText("5"); rcAux.setLayoutParams(new TableRow.LayoutParams(200, TableRow.LayoutParams.WRAP_CONTENT)); TextView tempAux = new TextView(this); tempAux.setText("9"); tempAux.setLayoutParams(new TableRow.LayoutParams(200, TableRow.LayoutParams.WRAP_CONTENT)); TextView radAux = new TextView(this); radAux.setText("10"); radAux.setLayoutParams(new TableRow.LayoutParams(100, TableRow.LayoutParams.WRAP_CONTENT)); rc.add(rcAux); temp.add(tempAux); rad.add(radAux); tr.addView(tvAux); tr.addView(rcAux); tr.addView(tempAux); tr.addView(radAux); tr.setBackgroundResource(R.drawable.tabla); // Asigna recurso de drawable a la row nueva tablaTL.addView(tr); } monitoreoHelper.empezarMonitoreo(); notificationIntent = new Intent(getApplicationContext(), NotificationActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: monitoreoHelper.terminarAlerta(); break; case DialogInterface.BUTTON_NEGATIVE: //No button clicked break; } } }; }
From source file:co.adrianblan.noraoke.SongNowPlayingFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_song_playing, container, false); ListView listView = (ListView) rootView.findViewById(R.id.now_playing_song_list); listView.setAdapter(new SongAdapter(getActivity(), 3)); //LinearLayout listHeaderView = (LinearLayout)inflater.inflate(R.layout.list_header, null); //listView.addHeaderView(listHeaderView); fab = (FloatingActionButton) rootView.findViewById(R.id.now_playing_fab); fab.attachToListView(listView);/*from w w w. ja va 2 s . c o m*/ fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), SongPlayingActivity.class); getActivity().startActivity(intent); } }); //Fulhaxx in order to preserve media player when fragment is destroyed if (mPlayer == null) { mPlayer = MediaPlayer.create(getActivity().getApplicationContext(), R.raw.iwantitthatway); } //Connect to the websocket if we don't have it if (mWebSocketClient == null) { connectWebSocket(); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { mPlayer.seekTo(0); } }; //Pressing the previous song button just starts it at the beginning final Button prev = (Button) rootView.findViewById(R.id.music_control_prev); prev.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.ic_skip_previous_black_24dp); prev.setOnClickListener(listener); final Button next = (Button) rootView.findViewById(R.id.music_control_next); next.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.ic_skip_next_black_24dp); next.setOnClickListener(listener); //Get music control play button play = (Button) rootView.findViewById(R.id.music_control_play); //Set the play button to its initial state if (mPlayer.isPlaying()) { play.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.ic_pause_black_24dp); } else { play.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.ic_play_arrow_black_24dp); } //Play and pause the song, also change the icons play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mPlayer.isPlaying()) { //Send the time in milliseconds if (mWebSocketClient.getReadyState() == WebSocket.READYSTATE.OPEN) { mWebSocketClient.send(System.currentTimeMillis() + " - " + mPlayer.getCurrentPosition()); } mPlayer.start(); play.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.ic_pause_black_24dp); } else { if (mWebSocketClient.getReadyState() == WebSocket.READYSTATE.OPEN) { mWebSocketClient.send("STOP"); } mPlayer.pause(); play.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, R.drawable.ic_play_arrow_black_24dp); } } }); //Get music control playlist button Button playlist = (Button) rootView.findViewById(R.id.music_control_playlist); //We switch the playlist visibility when we press the playlist button playlist.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LinearLayout playlist = (LinearLayout) rootView.findViewById(R.id.now_playing_playlist); if (playlist.getVisibility() != View.VISIBLE) { playlist.setVisibility(View.VISIBLE); Animation slideIn = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.slide_in); playlist.startAnimation(slideIn); fab.hide(); } else { Animation slideOut = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.slide_out); playlist.startAnimation(slideOut); playlist.setVisibility(View.GONE); fab.show(); } } }); rootView.findViewById(R.id.now_playing_playlist).setVisibility(View.GONE); ViewCompat.setElevation(rootView.findViewById(R.id.music_control), 50); return rootView; }
From source file:com.cypress.cysmart.BLEServiceFragments.CapsenseServiceProximity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.capsense_proximity, container, false); mproximityViewForeground = (ImageView) rootView.findViewById(R.id.proximity_view_1); mproximityViewBackground = (ImageView) rootView.findViewById(R.id.proximity_view_2); player = MediaPlayer.create(getActivity(), R.raw.beep); setHasOptionsMenu(true);//from w w w . j ava 2 s. c o m return rootView; }