| 1 | |
| 2 | // MainActivity.kt |
| 3 | |
| 4 | import android.content.pm.ActivityInfo |
| 5 | import android.os.Bundle |
| 6 | import androidx.appcompat.app.AppCompatActivity |
| 7 | import com.brightcove.player.display.ExoPlayerVideoDisplayComponent |
| 8 | import com.brightcove.player.event.Event |
| 9 | import com.brightcove.player.event.EventListener |
| 10 | import com.brightcove.player.event.EventType |
| 11 | import com.brightcove.player.model.DeliveryType |
| 12 | import com.brightcove.player.model.Video |
| 13 | import com.example.media3muxdata.databinding.ActivityMainBinding |
| 14 | import com.google.android.exoplayer2.ExoPlayer |
| 15 | import io.fastpix.data.domain.model.CustomDataDetails |
| 16 | import io.fastpix.data.domain.model.PlayerDataDetails |
| 17 | import io.fastpix.data.domain.model.VideoDataDetails |
| 18 | import io.fastpix.exoplayer_data_sdk.FastPixBaseExoPlayer |
| 19 | import java.util.UUID |
| 20 | |
| 21 | class MainActivity : BrightcovePlayer(), EventListener { |
| 22 | |
| 23 | private lateinit var binding: ActivityMainBinding |
| 24 | private lateinit var fastPixDataSDK: FastPixBaseExoPlayer |
| 25 | private lateinit var exoPlayer: ExoPlayer |
| 26 | |
| 27 | override fun onCreate(savedInstanceState: Bundle?) { |
| 28 | // Set up the layout and view binding |
| 29 | binding = ActivityMainBinding.inflate(layoutInflater) |
| 30 | setContentView(binding.root) |
| 31 | |
| 32 | // Call superclass constructor for lifecycle management |
| 33 | super.onCreate(savedInstanceState) |
| 34 | |
| 35 | // Create and configure the video for playback |
| 36 | val video = Video.createVideo( |
| 37 | “your-stream-url”, |
| 38 | DeliveryType.HLS |
| 39 | ) |
| 40 | |
| 41 | // Add the video to the player view and start playback |
| 42 | binding.playerView.add(video) |
| 43 | binding.playerView.start() |
| 44 | |
| 45 | // Register event listeners for fullscreen transitions |
| 46 | val emitter = binding.playerView.eventEmitter |
| 47 | emitter.on(EventType.ENTER_FULL_SCREEN, this) |
| 48 | emitter.on(EventType.EXIT_FULL_SCREEN, this) |
| 49 | |
| 50 | // Extract the ExoPlayer instance from Brightcove's video display component |
| 51 | val videoDisplayComponent = |
| 52 | binding.playerView.videoDisplay as ExoPlayerVideoDisplayComponent |
| 53 | exoPlayer = videoDisplayComponent.exoPlayer |
| 54 | |
| 55 | // Configure video metadata for analytics tracking |
| 56 | val videoDataDetails = VideoDataDetails( |
| 57 | UUID.randomUUID().toString(), // Unique video identifier |
| 58 | "Video Title" // Video display name |
| 59 | ).apply { |
| 60 | videoSeries = "Series Name" |
| 61 | videoProducer = "Producer Name" |
| 62 | videoContentType = "Content Type" |
| 63 | videoVariant = "Variant Info" |
| 64 | videoLanguage = "en" |
| 65 | } |
| 66 | |
| 67 | // Configure custom dimensions for business-specific tracking |
| 68 | val customDataDetails = CustomDataDetails() |
| 69 | customDataDetails.customField1 = "Custom Value 1" |
| 70 | customDataDetails.customField2 = "Custom Value 2" |
| 71 | |
| 72 | // Define player metadata for version tracking |
| 73 | val playerDataDetails = PlayerDataDetails( |
| 74 | playerName = "brightcove_player", |
| 75 | playerVersion = "9.2.3" |
| 76 | ) |
| 77 | |
| 78 | // Initialize FastPix Data SDK for analytics collection |
| 79 | fastPixDataSDK = FastPixBaseExoPlayer( |
| 80 | this, |
| 81 | playerView = binding.playerView, |
| 82 | exoPlayer = exoPlayer, |
| 83 | workSpaceId = "YOUR_WORKSPACE_ID", |
| 84 | videoDataDetails = videoDataDetails, |
| 85 | playerDataDetails = playerDataDetails, |
| 86 | enableLogging = true, |
| 87 | customDataDetails = customDataDetails |
| 88 | ) |
| 89 | } |
| 90 | |
| 91 | override fun processEvent(p0: Event) { |
| 92 | when (p0?.type) { |
| 93 | EventType.ENTER_FULL_SCREEN -> { |
| 94 | requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 95 | } |
| 96 | EventType.EXIT_FULL_SCREEN -> { |
| 97 | requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | override fun onDestroy() { |
| 103 | super.onDestroy() |
| 104 | fastPixDataSDK.release() |
| 105 | binding.playerView.clear() |
| 106 | } |
| 107 | |
| 108 | |
| 109 | } |