-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#378: sound on timer start and finish
- Loading branch information
1 parent
1461ffa
commit e176b01
Showing
10 changed files
with
166 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Friendly-plans/app/src/main/java/pg/autyzm/friendly_plans/child_app/utility/SoundHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pg.autyzm.friendly_plans.child_app.utility; | ||
|
||
import android.media.AudioManager; | ||
import android.media.MediaPlayer; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.inject.Inject; | ||
|
||
import database.repository.AssetRepository; | ||
import database.repository.ChildPlanRepository; | ||
import pg.autyzm.friendly_plans.AppComponent; | ||
import pg.autyzm.friendly_plans.asset.AssetsHelper; | ||
|
||
public class SoundHelper { | ||
@Inject | ||
ChildPlanRepository childPlanRepository; | ||
@Inject | ||
AssetsHelper assetsHelper; | ||
@Inject | ||
AssetRepository assetRepository; | ||
String loopSoundPath; | ||
public static SoundHelper getSoundHelper(AppComponent appComponent) | ||
{ | ||
SoundHelper soundHelper = new SoundHelper(); | ||
appComponent.inject(soundHelper); | ||
soundHelper.setLoopSoundPath(); | ||
return soundHelper; | ||
} | ||
|
||
void setLoopSoundPath() { | ||
Long soundId = childPlanRepository.getActivePlan().getChild().getTimerSoundId(); | ||
loopSoundPath = assetsHelper.getFileFullPath(assetRepository.get(soundId)); | ||
|
||
} | ||
|
||
public MediaPlayer prepareLoopSound() { | ||
MediaPlayer sound = new MediaPlayer(); | ||
try { | ||
sound.setDataSource(loopSoundPath); | ||
sound.setAudioStreamType(AudioManager.STREAM_MUSIC); | ||
sound.setLooping(true); | ||
sound.prepare(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return sound; | ||
} | ||
|
||
public void resetLoopSound(MediaPlayer sound){ | ||
sound.reset(); | ||
try { | ||
sound.setDataSource(loopSoundPath); | ||
sound.setAudioStreamType(AudioManager.STREAM_MUSIC); | ||
sound.setLooping(true); | ||
sound.prepare(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.