A cikin duniyar kafofin watsa labaru na zamani, ikon madauki mai kunna watsa labarai ya zama abin da ake nema sosai. Wannan gaskiya ne musamman ga waษancan lokutan da ba za mu iya samun isassun waฦa, bidiyo ko kowace hanyar sadarwa da muke jin daษin gaske ba. Maษallin mai kunna watsa labarai yana tabbatar da cewa abun cikin yana ci gaba da wasa, yana bawa masu amfani damar jin daษin sa ba tare da sake kunna shi da hannu ba. Wannan labarin yana magana ne akan yadda ake madauki na'urar mai jarida ta amfani da Java, sanannen yaren shirye-shirye, tare da zurfin jagorar mataki-mataki kan coding mafita. Bari yanzu mu nutse cikin looping na'urar mai jarida kuma mu bincika ษakunan karatu da ayyukan da ke cikin wannan tsari.
Amfani da Tsarin Media na Java (JMF) don madauki
Tsarin Watsa Labarai na Java (JMF) babban ษakin karatu ne mai ฦarfi wanda ke ba da damar haษaka aikace-aikacen multimedia a Java. Yana ba da tallafi don sauti, bidiyo, da sauran kafofin watsa labarai na lokaci, yana mai da shi kyakkyawan zaษi don aiwatar da ayyukan looping a cikin na'urar mai jarida. A cikin wannan sashe, za mu shiga cikin ษakin karatu na JMF kuma mu tattauna yadda ake madauki abun cikin kafofin watsa labarai ta amfani da bayanin mataki-mataki na lambar.
import javax.media.*; import java.net.*; public class MediaPlayerLooper { public static void main(String[] args) { try { // Create a media locator from a file URL MediaLocator mediaLocator = new MediaLocator(new URL("file:///path/to/media/file")); // Create a Player from the media locator Player player = Manager.createPlayer(mediaLocator); // Add a controller listener to the player player.addControllerListener(new ControllerAdapter() { @Override public void endOfMedia(EndOfMediaEvent e) { // Set media time to zero and restart the player player.setMediaTime(new Time(0)); player.start(); } }); // Start playing the media player.start(); } catch (Exception e) { e.printStackTrace(); } } }
Snippet ษin lambar da ke sama yana nuna matakai masu zuwa:
1. Shigo da JMF da sauran dakunan karatu masu mahimmanci
2. ฦirฦirar MediaPlayerLooper class
3. Yi amfani da MediaLocator don ฦirฦirar abu mai jarida
4. ฦirฦirar Dan wasa ta amfani da Manager aji tare da ฦayyadadden abin watsa labarai
5. aara a Mai Sauraron Sarrafa ga mai kunnawa don lura da canje-canjen jiharsa
6. Gudanar da taron 'endOfMedia', wanda ke faruwa lokacin da kafofin watsa labaru suka gama kunnawa, ta hanyar sake saita lokacin watsa labarai zuwa sifili da sake kunna mai kunnawa.
7. Fara kunna kafofin watsa labarai
Zazzagewa tare da MediaPlayer a cikin JavaFX
JavaFX wani mashahurin ษakin karatu ne don ฦirฦirar aikace-aikacen multimedia a Java. Nasa mai jarida aji yana ba da ginanniyar aikin madauki, yana mai da shi mafi sauฦi don madauki fayilolin mai jarida. A cikin wannan sashe, za mu bincika yin amfani da MediaPlayer na JavaFX don madauki abun cikin mai jarida.
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; import javafx.stage.Stage; import java.io.File; public class JavaFXMediaPlayerLooper extends Application { @Override public void start(Stage primaryStage) { File mediaFile = new File("path/to/media/file"); Media media = new Media(mediaFile.toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); MediaView mediaView = new MediaView(mediaPlayer); StackPane root = new StackPane(); root.getChildren().add(mediaView); Scene scene = new Scene(root, 800, 600); primaryStage.setTitle("Media Player Looper"); primaryStage.setScene(scene); primaryStage.show(); mediaPlayer.play(); } public static void main(String[] args) { launch(args); } }
Misalin lambar JavaFX da ke sama yana gabatar da matakai masu zuwa:
1. Shigo da ษakunan karatu na JavaFX
2. ฦirฦirar JavaFXMediaPlayerLooper class mikawa daga Aikace-aikace
3. Load da fayilolin mai jarida ta amfani da kafofin watsa labaru, class
4. ฦirฦirar mai jarida abu tare da ษimbin kafofin watsa labarai
5. Saita cycleCount sifa ta MediaPlayer zuwa BAYANI domin looping
6. ฦirฦirar MediaView abu kuma ฦara shi zuwa hoton wurin
7. Fara abubuwan haษin mai amfani, kamar mataki da fage
8. Fara kunna kafofin watsa labarai
A taฦaice, ana iya samun madaidaicin mai kunna mai jarida a Java ta amfani da dakunan karatu kamar JMF da JavaFX. Ta hanyar fahimtar ayyuka da azuzuwan da waษannan ษakunan karatu ke bayarwa, masu haษakawa na iya ฦirฦirar ingantattun aikace-aikace masu jan hankali waษanda ke biyan buฦatun kafofin watsa labarai na masu amfani.